Implement Ruby’s AppConfig file

2007 December 12
by Frank Mao

5DollarWhiteBox has a cool lib for ruby to utilize Unix style config file, like:

serverID = web01
serverIPAddress = 192.168.1.102

I tried, it works OK. The only problem is one of my settings has a equal sign in it. This parser then screwed up.

myUrl = http://someghing.com?myId=123

So, xml config is the only option for me, and it’s more popular and cross-platform. By using ruby standard lib ‘rexml/document’, the following configuration can be easily parsed out.

conf_file:
<justing>
<rss_feed_url>http://podcast.overseakids.com/justing_history.xml</rss_feed_url>
</justing>

require ‘rexml/document’
doc = REXML::Document.new(File.new(conf_file))
rss_feed_url = doc.elements['justing/rss_feed_url'].text

2 Responses leave one →
  1. 2008 July 20

    Just notice this comment about ParseConfig. Wanted to drop a line and let you know this issue was fixed a while back:

    Changes:
    Thu Feb 28, 2008 – v0.4.2
    - Fixed bug where if the value contains a ‘=’ then the parameter
    is not properly set. [bjd]
    - Fixed bug #13680 Unable to parse config options that contain
    single quotes. [bjd]

    Please let me know if you find any other issues with it… and thanks for the mention!

  2. 2008 July 21

    Thanks for the update. Nice to see an active ruby project going on.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS