Implement Ruby’s AppConfig file

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&gt;
</justing>

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

Advertisements

2 thoughts on “Implement Ruby’s AppConfig file

  1. 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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s