From: "Ara.T.Howard" Date: 2003-12-19T02:11:56+09:00 Subject: Re: Configuration Files On Thu, 18 Dec 2003, Gavin Sinclair wrote: > Date: Thu, 18 Dec 2003 13:51:45 +0900 > From: Gavin Sinclair > Newsgroups: comp.lang.ruby > Subject: Re: Configuration Files > > > > > 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 have a really cool way of specifying config files. It goes like this: > > plugin: > player: > class: CommandPlayer > command: mpg123 > > However, the code for parsing this is a secret :) i'm with you (and use it myself), but the above is problematic if you actually want non-programmers to be able to _configure_ a system. for example, how long do you think it would take a non-programmer to debug this? file config.rb: ======== require 'yaml' config = <<-txt plugin: player: class: CommandPlayer command: mpg123 txt YAML::load(config) ~/eg/ruby > ruby config.rb /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load': parse error on line 3, col 12: ` command: mpg123' (ArgumentError) from /data/ruby-1.8.0//lib/ruby/1.8/yaml.rb:39:in `load' from config.rb:8 -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================