Need library for parsing configuration files

From: T. Onoma [mailto:transami@runbox.com]
Subject: Re: Need library for parsing configuration files

hi,
i’m writing an application which needs to parse a
configuration file on
program startup. is there a prefered format for
configuration files in
ruby? is there a library for such a purpose? i suppose i
could do the
parsing myself, but i was just wondering if there is a
sophisticated way
out there.

thank you

I would consider Yaml.

Yaml is human-readable-and-writable, agreed, but only if the human is a programmer :slight_smile:
Actually the problem is that i want configuration values segregated into different groups.
Users would find the Yaml syntax which requires indentation esoteric.

how feasible is it to use Kernel::load() ?
maybe i should let the user modify a ruby source-file, which looks kind of like this

application.ui = true #true, false
window.size = 1000 # 250 - 3000
images.max = 10 # 1 - 50

and then load this file at an appropriate time.
is this a feasible way to do things?

-t0

Gavri Savio Fernandez

···

-----Original Message-----


If only God would give me some clear sign! Like making a large deposit in my name at a Swiss bank. - Woody Allen

“Gavri Savio Fernandez” Gavri_F@infosys.com schrieb im Newsbeitrag
news:557E17BE74D22143B7BE70EB60E33E9909196571@shlmsg01.ad.infosys.com

From: T. Onoma [mailto:transami@runbox.com]
Subject: Re: Need library for parsing configuration files

hi,
i’m writing an application which needs to parse a
configuration file on
program startup. is there a prefered format for
configuration files in
ruby? is there a library for such a purpose? i suppose i
could do the
parsing myself, but i was just wondering if there is a
sophisticated way
out there.

thank you

I would consider Yaml.

Yaml is human-readable-and-writable, agreed, but only if the human is a
programmer :slight_smile:
Actually the problem is that i want configuration values segregated into
different groups.
Users would find the Yaml syntax which requires indentation esoteric.

how feasible is it to use Kernel::load() ?
maybe i should let the user modify a ruby source-file, which looks kind
of like this

application.ui = true #true, false
window.size = 1000 #
250 - 3000
images.max = 10 #
1 - 50

and then load this file at an appropriate time.
is this a feasible way to do things?

Like this?

class Config
def initialize
@values = {}
end

def method_missing(sym,*args)
s = sym.to_s.freeze

if s[-1] == ?=
  # setter
  @values[s] = args.size == 1 ? args[0] : args
else
  # getter
  @values[s] ||= self.class.new
end

end

def load(file)
instance_eval File.readlines(file, nil).shift
end

def self.load(file)
conf = self.new
conf.load file
conf
end
end

conf = Config.new

conf.load “conf.rc”
p conf

conf = Config.load “conf.rc”
p conf

Regards

robert
···

-----Original Message-----