# Configuration Files

**URL:** <https://rubytalk.org/t/configuration-files/9389>\
**Category:** ruby-talk\
**Created:** [18 December 2003 18:13 UTC](https://rubytalk.org/t/configuration-files/9389 "2003-12-18T18:13:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [18 December 2003 18:13 UTC](https://rubytalk.org/t/configuration-files/9389/1 "2003-12-18T18:13:52Z")

</div>

> Subject: Re: Configuration Files  
> From: “Ara.T.Howard” [ahoward@ngdc.noaa.gov](mailto:ahoward@ngdc.noaa.gov)  
> Date: Fri, 19 Dec 2003 02:11:56 +0900  
> References: 88419 88424 88427  
> In-reply-to: 88427
> 
> > Date: Thu, 18 Dec 2003 13:51:45 +0900  
> > From: Gavin Sinclair [gsinclair@soyabean.com.au](mailto:gsinclair@soyabean.com.au)  
> > 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.

> **···**
>
> > On Thu, 18 Dec 2003, Gavin Sinclair wrote:
> 
> > -a

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ara.T.Howard2](https://rubytalk.org/u/Ara.T.Howard2)\
**Post date:** [18 December 2003 22:02 UTC](https://rubytalk.org/t/configuration-files/9389/2 "2003-12-18T22:02:05Z")

</div>

> Date: Fri, 19 Dec 2003 03:13:52 +0900  
> From: Gennady [gfb@tonesoft.com](mailto:gfb@tonesoft.com)  
> Newsgroups: comp.lang.ruby  
> Subject: Re: Configuration Files

\> \> file config.rb: \> \> ======== \> \> require 'yaml' \> \> config = \< \> 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. 

it may seem like cheating, but i spent twenty minutes debugging something just  
like this after advocating yaml based configs here at work and letting a real  
live user configure something - which immeadiately broke my software!

> 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

well - i now do too. the question is, why doesn’t yaml? currently i’m simply  
gsub’ing tabs for eight spaces and figure this _shouldn’t_ breaky anything but  
haven’t really looked into further. i posted something a while back wondering  
if trailing space is _ever_ required in yaml, eg if it’s o.k.  
to do this?

def parse file  
buf = file.respond\_to?(:read) ? file.read : open(file){|f| f.read}  
buf.gsub! %r/\s+$/, ‘’  
YAML::load(buf)  
end

i guess i need to rtfm…

-a

> **···**
>
> ## On Fri, 19 Dec 2003, Gennady wrote:
> 
> 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 :: [Solar-Terrestrial Physics Data | NCEI](http://www.ngdc.noaa.gov/stp/)  
> > NGDC :: [http://www.ngdc.noaa.gov/](http://www.ngdc.noaa.gov/)  
> > NESDIS :: [http://www.nesdis.noaa.gov/](http://www.nesdis.noaa.gov/)  
> > NOAA :: [http://www.noaa.gov/](http://www.noaa.gov/)  
> > US DOC :: [http://www.commerce.gov/](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’  
> > ===============================================================================

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [18 December 2003 22:10 UTC](https://rubytalk.org/t/configuration-files/9389/3 "2003-12-18T22:10:20Z")

</div>

> > I just got it :-). However it seems like cheating 😉 – there were no  
> > tabs in Gavin’s example.

> it may seem like cheating, but i spent twenty minutes debugging something just  
> like this after advocating yaml based configs here at work and letting a real  
> live user configure something - which immeadiately broke my software!

Interesting. Thanks for the warning.

> > 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

> well - i now do too. the question is, why doesn’t yaml? currently i’m simply  
> gsub’ing tabs for eight spaces and figure this _shouldn’t_ breaky anything but  
> haven’t really looked into further. i posted something a while back wondering  
> if trailing space is _ever_ required in yaml

I guess that’s up to the user. Iff you know that no trailing spaces  
are allowed in your domain, then remove them.

As for tabs, I would simply error out and tell the user to get rid of  
that tabs. Assigning a different number of spaces to a tab means  
you’ll get different interpretations of the document, I think.

Perhaps YAML could include one or two methods to do this kind of  
common pre-processing, so we don’t all duplicate the code?

Gavin

> **···**
>
> On Friday, December 19, 2003, 9:02:05 AM, Ara.T.Howard wrote:

---

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [18 December 2003 22:26 UTC](https://rubytalk.org/t/configuration-files/9389/4 "2003-12-18T22:26:33Z")

</div>

I use Austin Ziegler’s Text::Format for expanding tabs. Works great for  
me, and for yaml 😉

Gennady.

Gavin Sinclair wrote:

> **···**
>
> > On Friday, December 19, 2003, 9:02:05 AM, Ara.T.Howard wrote:
> > 
> > > > I just got it :-). However it seems like cheating 😉 – there were no  
> > > > tabs in Gavin’s example.
> > 
> > > it may seem like cheating, but i spent twenty minutes debugging something just  
> > > like this after advocating yaml based configs here at work and letting a real  
> > > live user configure something - which immeadiately broke my software!
> > 
> > Interesting. Thanks for the warning.
> > 
> > > > 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
> > 
> > > well - i now do too. the question is, why doesn’t yaml? currently i’m simply  
> > > gsub’ing tabs for eight spaces and figure this _shouldn’t_ breaky anything but  
> > > haven’t really looked into further. i posted something a while back wondering  
> > > if trailing space is _ever_ required in yaml
> > 
> > I guess that’s up to the user. Iff you know that no trailing spaces  
> > are allowed in your domain, then remove them.
> > 
> > As for tabs, I would simply error out and tell the user to get rid of  
> > that tabs. Assigning a different number of spaces to a tab means  
> > you’ll get different interpretations of the document, I think.
> > 
> > Perhaps YAML could include one or two methods to do this kind of  
> > common pre-processing, so we don’t all duplicate the code?
> > 
> > Gavin

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ara.T.Howard2](https://rubytalk.org/u/Ara.T.Howard2)\
**Post date:** [19 December 2003 02:51 UTC](https://rubytalk.org/t/configuration-files/9389/5 "2003-12-19T02:51:56Z")

</div>

**exactly** what i’m hoping for. it’s easy enough to process tabs in a  
particular way, but it makes me queasy since the YAML spec might change, etc.  
now, if the methods were part of yaml4r then i can simply use them and  
complain to someone else when they break! (sorry \_why) 😉

plus - the file/string doesn’t need processing twice…

my 2cents. for now, i’m simply blowing away tabs.

-a

> **···**
>
> On Fri, 19 Dec 2003, Gavin Sinclair wrote:
> 
> > Date: Fri, 19 Dec 2003 07:10:20 +0900  
> > From: Gavin Sinclair [gsinclair@soyabean.com.au](mailto:gsinclair@soyabean.com.au)  
> > Newsgroups: comp.lang.ruby  
> > Subject: Re: Configuration Files
> > 
> > On Friday, December 19, 2003, 9:02:05 AM, Ara.T.Howard wrote:
> > 
> > > > I just got it :-). However it seems like cheating 😉 – there were no  
> > > > tabs in Gavin’s example.
> > 
> > > it may seem like cheating, but i spent twenty minutes debugging something just  
> > > like this after advocating yaml based configs here at work and letting a real  
> > > live user configure something - which immeadiately broke my software!
> > 
> > Interesting. Thanks for the warning.
> > 
> > > > 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
> > 
> > > well - i now do too. the question is, why doesn’t yaml? currently i’m simply  
> > > gsub’ing tabs for eight spaces and figure this _shouldn’t_ breaky anything but  
> > > haven’t really looked into further. i posted something a while back wondering  
> > > if trailing space is _ever_ required in yaml
> > 
> > I guess that’s up to the user. Iff you know that no trailing spaces  
> > are allowed in your domain, then remove them.
> > 
> > As for tabs, I would simply error out and tell the user to get rid of  
> > that tabs. Assigning a different number of spaces to a tab means  
> > you’ll get different interpretations of the document, I think.
> > 
> > Perhaps YAML could include one or two methods to do this kind of  
> > common pre-processing, so we don’t all duplicate the code?
> 
> –
> 
> 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 :: [Solar-Terrestrial Physics Data | NCEI](http://www.ngdc.noaa.gov/stp/)  
> > NGDC :: [http://www.ngdc.noaa.gov/](http://www.ngdc.noaa.gov/)  
> > NESDIS :: [http://www.nesdis.noaa.gov/](http://www.nesdis.noaa.gov/)  
> > NOAA :: [http://www.noaa.gov/](http://www.noaa.gov/)  
> > US DOC :: [http://www.commerce.gov/](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’  
> > ===============================================================================
