5dollarwhitebox.org - theboxownsyou

  • blog
  • projects
  • articles
  • tech wiki
  • about
  • login
Home › Blogs › drks's blog

RSS Feed

Ruby ParseConfig 0.5 Released - Easily Parse Standard *Nix Style Config Files

drks — Mon, 2009-09-21 17:35

Latest update of the Ruby ParseConfig library adds a few new features, including the ability to do [grouping]. For example, reading a MySQL config file:

#!/usr/bin/ruby
 
require('rubygems')
require('parseconfig')
 
c = ParseConfig.new('./my.cnf')
puts
puts "Available config groups: #{c.groups}"
puts
puts "config['client']['user'] => #{c.params['client']['user']}"
puts "config['client']['password'] => #{c.params['client']['password']}"
puts

And the output:

you@linuxbox ~] $ cat ./my.cnf 
 
[client]
user=johnny
password=3uS1F1eufy75
 
 
you@linuxbox ~] $ ruby ./read_my_cnf.rb
 
Available config groups: client
 
config['client']['user'] => johnny
config['client']['password'] => 3uS1F1eufy75



The following changes have been applied.

Mon Aug 31, 2009 - v0.5
- Added sub-groups feature per RubyForge tracker [#27019].  Config files
  can now have [subgroups] whose values are added to a nested Hash object.
- Added the write() function per RubyForge tracker [#27019].  Will print 
  to STDOUT by default, or to a file object if passed.
- Added the add(), and add_to_group() functions to support new features
  per RubyForge tracker [#27019].
- Thank you to Titouan Christophe for the submissions listed above!
- ParseConfig.get_params() returns all params including groups.  
  ParseConfig.get_groups() returns available sub-groups.
- See the demo.rb and demo.conf files which have been updated to reflect
  this update.
- The methods override_value() and nil_value() are now deprecated and will
  be removed in future versions.


Installing

The ParseConfig library is available via Ruby Gems, simply execute the following on your linux box:

you@linuxbox ~] $ sudo gem install parseconfig


Reporting Bugs or Feature Requests

Bugs and Feature Requests can be reported to the RubyForge Project Page.


More Reading About ParseConfig

For a bit of history on ParseConfig and how to use it, feel free to check out the original article I wrote:

* Ruby Configuration File Parser
* Ruby ParseConfig Demo



  • drks's blog

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

nice

Brent Lintner (not verified) — Mon, 2010-01-18 17:08

Now it is I who googles a ruby config parser and voila. Great gem, I may just utilize it, rather then write a shabby class myself lol.

Cheers,

Brent.

  • reply

Thanks, your website is very

odżywki (not verified) — Mon, 2009-09-28 11:08

Thanks, your website is very helpful

  • reply

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
Input format
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <c>, <cpp>, <diff>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <perl>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options



Who's online

There are currently 0 users and 1 guest online.
  • blog
  • projects
  • articles
  • tech wiki
  • about
  • login

5dollarwhitebox.org is not responsible in anyway for actions performed based on information found on this site.