[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Config files

Lee Jarvis

10/1/2007 11:21:00 PM

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

Thanks
--
Posted via http://www.ruby-....

7 Answers

Konrad Meyer

10/2/2007 12:20:00 AM

0

Quoth Lee Jarvis:
> I am writing an application that will read and grab values from a
> configuration file. I am wondering what peoples opinions are on what to
> use. YAML? XML? Does anyone have any preference? Are any better then the
> others or is it just down to user preference?
>
> Thanks

Personally, I think XML is a load of crap. If your configuration is simple
enough (and it likely is) I'd use YAML. If you need anything more
complicated, you can always use your own scheme, Marshal, or a sqlite db or
something.

Regards,
--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertil...

BJ Dierkes

10/2/2007 3:27:00 AM

0

I prefer using standard *nix style configuration files in the form of
'param = value'. I wrote a class to read this type of configuration
file called ParseConfig.

http://rubyforge.org/projects/pa...


It is available via rubygems/rubyforge:

gem install parseconfig


Usage is really simple. Say you have a config file that looks like:

---
user = 'username'
pass = 'password'
log_file = '/var/log/mylog'
---

A quick example to use this config would be:
---
require('rubygems')
require('parseconfig')

config = ParseConfig.new('/path/to/config/file')
user = config.get_value('user')
pass = config.get_value('pass')
log_file = config.get_value('log_file')
---


If you all have any suggestions, etc... you can submit them via the
RubyForge Tracker.


On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:

> I am writing an application that will read and grab values from a
> configuration file. I am wondering what peoples opinions are on
> what to
> use. YAML? XML? Does anyone have any preference? Are any better
> then the
> others or is it just down to user preference?
>
> Thanks
> --
> Posted via http://www.ruby-....
>


Dejan Dimic

10/2/2007 6:46:00 AM

0

On Oct 2, 5:26 am, BJ Dierkes <wdier...@5dollarwhitebox.org> wrote:
> I prefer using standard *nix style configuration files in the form of
> 'param = value'. I wrote a class to read this type of configuration
> file called ParseConfig.
>
> http://rubyforge.org/projects/pa...
>
> It is available via rubygems/rubyforge:
>
> gem install parseconfig
>
> Usage is really simple. Say you have a config file that looks like:
>
> ---
> user = 'username'
> pass = 'password'
> log_file = '/var/log/mylog'
> ---
>
> A quick example to use this config would be:
> ---
> require('rubygems')
> require('parseconfig')
>
> config = ParseConfig.new('/path/to/config/file')
> user = config.get_value('user')
> pass = config.get_value('pass')
> log_file = config.get_value('log_file')
> ---
>
> If you all have any suggestions, etc... you can submit them via the
> RubyForge Tracker.
>
> On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:
>
> > I am writing an application that will read and grab values from a
> > configuration file. I am wondering what peoples opinions are on
> > what to
> > use. YAML? XML? Does anyone have any preference? Are any better
> > then the
> > others or is it just down to user preference?
>
> > Thanks
> > --
> > Posted viahttp://www.ruby-....

As told so menu times before: There is no golden hammer.
The optimal solution depends on your application needs and estimation
about future use of it.
The yaml is more human readable. XML is universal and can be used by
other applications but has some overhead. Classical config files are
something programmers used to and it's portable and more or less human
readable. There is also a data base configuration but that is out of
the scope because you should have configuration for database that
holds configurations for application.

Personally, the yaml version is a way to start. If some need emerge
that can't be natively expressed by yaml than you should move to other
solution. But most probably you will stay on yaml.

Phil Meier

10/2/2007 6:53:00 AM

0

I like using Ruby directly for doing stuff like this (if the
"configuration file" is under my control).

Example:
module MyConfig
user = 'username'
pass = 'password'
log_file = '/var/log/mylog'
end
=> Store in file 'MyConfig.rb'

test.rb:
require 'MyConfig'

p MyConfig::User
p MyConfig::Pass
p MyConfig::Log_file

BR Phil Meier


BJ Dierkes schrieb:
> I prefer using standard *nix style configuration files in the form of
> 'param = value'. I wrote a class to read this type of configuration
> file called ParseConfig.
>
> http://rubyforge.org/projects/pa...
>
>
> It is available via rubygems/rubyforge:
>
> gem install parseconfig
>
>
> Usage is really simple. Say you have a config file that looks like:
>
> ---
> user = 'username'
> pass = 'password'
> log_file = '/var/log/mylog'
> ---
>
> A quick example to use this config would be:
> ---
> require('rubygems')
> require('parseconfig')
>
> config = ParseConfig.new('/path/to/config/file')
> user = config.get_value('user')
> pass = config.get_value('pass')
> log_file = config.get_value('log_file')
> ---
>
>
> If you all have any suggestions, etc... you can submit them via the
> RubyForge Tracker.
>
>
> On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:
>
>> I am writing an application that will read and grab values from a
>> configuration file. I am wondering what peoples opinions are on what to
>> use. YAML? XML? Does anyone have any preference? Are any better then the
>> others or is it just down to user preference?
>>
>> Thanks
>> --
>> Posted via http://www.ruby-....
>>
>
>

Paul Van Delst

10/2/2007 10:36:00 PM

0

Lee Jarvis wrote:
> I am writing an application that will read and grab values from a
> configuration file. I am wondering what peoples opinions are on what to
> use. YAML? XML? Does anyone have any preference? Are any better then the
> others or is it just down to user preference?

I tried to roll my own once - and now I use yaml. :o) Nice and simple, easy to use for
both simple and complicated[*] configuration files, and you can go on with more
interesting stuff.

Besides, whichever you choose, you can always change it if your application outgrows it,
right?

cheers,

paulv

[*] Well, actually, in this case it wasn't a configuration file per se, but a
specification for a derived type definition in Fortran95 along with associated netcdf
attributes for I/O. Works a treat, though.

James Gray

10/2/2007 11:01:00 PM

0

On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:

> I am writing an application that will read and grab values from a
> configuration file. I am wondering what peoples opinions are on
> what to
> use. YAML? XML? Does anyone have any preference? Are any better
> then the
> others or is it just down to user preference?

YAML tends to work out well, when it's very simple data fields being
collected. That said, YAML's syntax rules are quite complex and
asking a user to edit any non-trivial data in the format is a bad
idea, in my opinion.

If you need markup at all, use XML. It's a markup language, after
all. YAML is not.

Also, while more verbose, XML has a much easier syntax that far more
people are familiar with. I'm not saying that means you have to use
it, but it's something to stay aware of.

Finally, I've used this trick a couple of times now and I just love it:

#!/usr/bin/env ruby -wKU

require "ostruct"

module Config
module_function

def load_config_file(path)
eval <<-END_CONFIG
config = OpenStruct.new
#{File.read(path)}
config
END_CONFIG
end
end

__END__

That let's me do my configurations in pure Ruby, which may or may not
be appropriate for your needs.

I guess the most important thing is to consider your audience.

James Edward Gray II


Terry Poulin

10/3/2007 9:24:00 PM

0

BJ Dierkes wrote:
> I prefer using standard *nix style configuration files in the form of
> 'param = value'. I wrote a class to read this type of configuration
> file called ParseConfig.
>
> http://rubyforge.org/projects/pa...
>
>

Ooo, thank you.. I've been meaning to look for some thing like that :-)




I have actually never needed to deal with config files from this perspective.
Personally from the point of view of Joe Blow. I prefer a syntax like most
unix style config files.

# Comment
parm = value

Along with the ini file, it makes for a very easy to edit file. It's just a
matter of figuring out what does what for the end user. (IMHO)


TerryP.


--

Email and shopping with the feelgood factor!
55% of income to good causes. http://www.ip...