File: README.md

package info (click to toggle)
ruby-parseconfig 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 72 kB
  • ctags: 11
  • sloc: ruby: 112; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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](https://secure.travis-ci.org/derks/ruby-parseconfig.png)](http://travis-ci.org/derks/ruby-parseconfig)

Installation
------------

    $ sudo gem install 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.rb')
    => true
    
    >> config = ParseConfig.new('/path/to/config/file')
    => #<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"


License
-------

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