That sounds like a great config file system. I rolled my own basic one not too long ago, but having seen this, I'm thinking I'd replace it. :) One thing I did in mine which I kind of like, but has drawbacks, is a sort of grouping, where: [plugin.player] class=CommandPlayer command=mpg123 is the same as: plugin.player.class=CommandPlayer plugin.player.command=mpg123 I didn't have any equivalent of [/plugin.player] though, so once you're in a group, you couldn't define top-level elements any more, and there's no way to nest the groups. Even despite that, I really like being able to group someone to avoid having to duplicate the "plugin.player", because sometimes there's 15 or so config elements in a group. On Thu, 18 Dec 2003, John W. Long wrote: > A while back someone submitted some code to this list for evaluating > Configuration files in the style of: > > % cat test.config > editor.spacespertab = 4 > toolbar.visible = true > statusbar.visible = false > . . . > > One of the great things about their code was that it enabled you to use ruby > code within your configuration file so you could do things like this: > > %cat test2.config > timer.alarm = 30 * 60 # set the timer to go off in 30 min > > Their implementation was pretty simple. Mainly they created a hash, > splitting each line on /=/, and evaled the right side and stored the result > in the hash with a key of the left side. > > I like this concept, but I wanted a better implementation. So I set to work > and created the attached files. The attached now enables you to do this: > > %cat myprog.rb > require 'config' > > $conf = Config.new > > # set up the default values and configuration structure: > $conf.define %{ > editor.spacespertab = 8 > toolbar.visible = false > toolbar.caption = "Tools" > statusbar.visible = true > copyright = "Copyright © 2003, John W. Long" > } > > $conf.read File.new('test.config', 'r').read > > # you can even read multi line ruby snippets: > $conf.read %{ > copyright = "Copyright © 2003, John W. Long > All Rights Reserved" > alarm = 30 * 60 #seconds > } > > # now for getting the values, note the object hierarchy > toolbar.caption = $conf.toolbar.caption.value > toolbar.show if $conf.toolbar.visible.value > aboutbox.copyright = $conf.copyright.value > . . . > > You get the idea. > > A couple of advantages that this has over the previous concept: > -- You define the default values and create the config structure at the same > time > -- Because you define a config structure if someone makes a typo in the > config file misspelling "toolbar" as "tolbar" an error will be thrown > (eventually it will even tell you what line the error was on) > -- You access the values from the config file in almost the same way that > they are written into the config file on your Config object > > I didn't attach the unit tests of this version because the code still > relatively crude. Once I get things worked out a bit I may post it on > RubyForge. > > Feedback is appreciated. > > ___________________ > John Long > www.wiseheartdesign.com > Derek Lewis =================================================================== Java Web-Application Developer Email : email / lewisd.com Cellular : 604.312.2846 Website : http://www.lewisd.com "If you've got a 5000-line JSP page that has "all in one" support for three input forms and four follow-up screens, all controlled by "if" statements in scriptlets, well ... please don't show it to me :-). Its almost dinner time, and I don't want to lose my appetite :-)." - Craig R. McClanahan