From: Gennady Date: 2003-12-19T03:13:52+09:00 Subject: Re: Configuration Files > Subject: Re: Configuration Files > From: "Ara.T.Howard" > Date: Fri, 19 Dec 2003 02:11:56 +0900 > References: 88419 88424 88427 > In-reply-to: 88427 > > 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 I just got it :-). However it seems like cheating ;-) -- there were no tabs in Gavin's example. There are lots of issues with TABs in yaml, we all know. The common approach is just to avoid them alltogether. I usually "untab" config files before calling YAML::load Gennady. > > -a