Ruby Config File Parser for Standard Unix/Linux Type Config Files
Ruby Shell
Switch branches/tags
Nothing to show
Latest commit 8d3a16f Jan 26, 2016 @derks derks Resolves Issue #31
Permalink
Failed to load latest commit information.
doc Resolves Issue #31 Jan 26, 2016
lib Resolves Issue #31 Jan 26, 2016
tests Resolves Issue #31 Jan 26, 2016
utils Bumping version to 1.0.6 stable Oct 6, 2014
.travis.yml Test on Ruby 2.2 Jan 25, 2016
CREDITS Adding Tim Ekl to CREDITS Jun 12, 2012
Changelog Resolves Issue #31 Jan 26, 2016
LICENSE Update Year Jan 25, 2016
README.md Resolves Issue #31 Jan 26, 2016
parseconfig.gemspec Resolves Issue #31 Jan 26, 2016

README.md

Ruby ParseConfig Library

ParseConfig provides simple parsing of standard configuration files in the form of param = value. It also supports nested [group] sections.

Continuous Integration Status

Installation

$ gem install parseconfig

Gemfile

gem 'parseconfig'

Usage

An example configuration file might look like:

# Example Config
param1 = value1
param2 = value2

[group1]
group1_param1 = group1_value1
group1_param2 = group1_value2

[group2]
group2_param1 = group2_value1
group2_param2 = group2_value2

Access it with ParseConfig:

>> require 'parseconfig'
=> true

>> config = ParseConfig.new('/path/to/config/example.conf')
=> #<ParseConfig:0x102410908
      @config_file="example.conf",
      @groups=["group1", "group2"],
      @params={
            "param1"=>"value1"
            "param2"=>"value2",
            "group1"=>{
                "param1"=>"value1"
                "param2"=>"value2",
            },
            "group2"=>{
                "param1"=>"value1"
                "param2"=>"value2",
            },
    }>

>> config.get_params
=> ["param1", "param2", "group1", "group2"]

>> config['param1']
=> "value1"

>> config.get_groups
=> ["group1", "group2"]

>> config['group1']
=> {"group1_param1"=>"group1_value1", "group1_param2"=>"group1_value2"}

>> config['group1']['group1_param1']
=> "group1_value1"

>> file = File.open('/path/to/config/file', 'w')
=> #<File:file>

>> config.write(file)
=> []

>> file.close
=> nil

License

The ParseConfig library is Open Source and distributed under the MIT license. Please see the LICENSE file included with this software.