parseconfig 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog +4 -0
- data/LICENSE +1 -1
- data/README.md +19 -18
- data/lib/parseconfig.rb +22 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e211188d856835d945577417f00876882067caa2
|
4
|
+
data.tar.gz: 8004e0a522105456dde4bf1d35c0c6ac0c4c1bce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98046197998f9eca8c26805de80a7362776a56b9172312a71d3d8963e3eb9dbfc627248180ab847476e9a7d009a8dff32b3cefa2d787d891b8cc569322fa6c14
|
7
|
+
data.tar.gz: ba8a718dfd8a99c6ee194b97f1be7d92cb562a49a4fcab0752c320d0605325244f3c002777762bfc8fd1f642a6ea1c78dd496a24f8d77ec0b64d6c7739d97d84
|
data/Changelog
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
Mon Jan 25, 2016 - v1.0.7
|
2
|
+
- Support alternative comment types (default: ['#', ';']) (@voobscout)
|
3
|
+
Resolves Issue #30
|
4
|
+
|
1
5
|
Mon Oct 06, 2014 - v1.0.6
|
2
6
|
- Fix where extraneous double quotes were getting wrapped around parameters
|
3
7
|
that have non-word characters (issue #19)
|
data/LICENSE
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
The MIT License:
|
3
3
|
|
4
|
-
Copyright (c) 2006-
|
4
|
+
Copyright (c) 2006-2016 Data Folk Labs, LLC
|
5
5
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
Ruby ParseConfig Library
|
2
|
-
========================
|
1
|
+
# Ruby ParseConfig Library
|
3
2
|
|
4
3
|
ParseConfig provides simple parsing of standard configuration files in the
|
5
4
|
form of 'param = value'. It also supports nested [group] sections.
|
@@ -9,34 +8,37 @@ form of 'param = value'. It also supports nested [group] sections.
|
|
9
8
|
Installation
|
10
9
|
------------
|
11
10
|
|
12
|
-
|
11
|
+
```
|
12
|
+
$ sudo gem install parseconfig
|
13
|
+
```
|
13
14
|
|
14
15
|
Gemfile
|
15
16
|
|
16
|
-
|
17
|
+
```
|
18
|
+
gem 'parseconfig'
|
19
|
+
```
|
17
20
|
|
18
|
-
Usage
|
19
|
-
-----
|
21
|
+
## Usage
|
20
22
|
|
21
23
|
An example configuration file might look like:
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
```
|
26
|
+
# Example Config
|
27
|
+
param1 = value1
|
28
|
+
param2 = value2
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
[group1]
|
31
|
+
group1_param1 = group1_value1
|
32
|
+
group1_param2 = group1_value2
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
[group2]
|
35
|
+
group2_param1 = group2_value1
|
36
|
+
group2_param2 = group2_value2
|
34
37
|
|
35
38
|
|
36
39
|
Access it with ParseConfig:
|
37
40
|
|
38
41
|
```ruby
|
39
|
-
|
40
42
|
>> require 'parseconfig'
|
41
43
|
=> true
|
42
44
|
|
@@ -81,8 +83,7 @@ Access it with ParseConfig:
|
|
81
83
|
|
82
84
|
```
|
83
85
|
|
84
|
-
License
|
85
|
-
-------
|
86
|
+
## License
|
86
87
|
|
87
88
|
The ParseConfig library is Open Source and distributed under the MIT license.
|
88
89
|
Please see the LICENSE file included with this software.
|
data/lib/parseconfig.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: BJ Dierkes <derks@datafolklabs.com>
|
3
|
-
# Copyright:: Copyright (c) 2006,
|
3
|
+
# Copyright:: Copyright (c) 2006,2016 Data Folk Labs, LLC
|
4
4
|
# License:: MIT
|
5
5
|
# URL:: https://github.com/datafolklabs/ruby-parseconfig
|
6
6
|
#
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
class ParseConfig
|
20
20
|
|
21
|
-
Version = '1.0.
|
21
|
+
Version = '1.0.7'
|
22
22
|
|
23
23
|
attr_accessor :config_file, :params, :groups
|
24
24
|
|
@@ -28,10 +28,12 @@ class ParseConfig
|
|
28
28
|
# the config file is 'param = value' then the itializer
|
29
29
|
# will eval "@param = value"
|
30
30
|
#
|
31
|
-
def initialize(config_file=nil)
|
31
|
+
def initialize(config_file=nil, separator='=', comments: ['#', ';'])
|
32
32
|
@config_file = config_file
|
33
33
|
@params = {}
|
34
34
|
@groups = []
|
35
|
+
@splitRegex = '\s*' + separator + '\s*'
|
36
|
+
@comments = comments
|
35
37
|
|
36
38
|
if(self.config_file)
|
37
39
|
self.validate_config()
|
@@ -64,9 +66,17 @@ class ParseConfig
|
|
64
66
|
rescue NoMethodError
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
is_comment = false
|
70
|
+
@comments.each do |comment|
|
71
|
+
if (/^#{comment}/.match(line))
|
72
|
+
is_comment = true
|
73
|
+
break
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
unless is_comment
|
78
|
+
if(/#{@splitRegex}/.match(line))
|
79
|
+
param, value = line.split(/#{@splitRegex}/, 2)
|
70
80
|
var_name = "#{param}".chomp.strip
|
71
81
|
value = value.chomp.strip
|
72
82
|
new_value = ''
|
@@ -124,11 +134,15 @@ class ParseConfig
|
|
124
134
|
|
125
135
|
# This method adds an element to the config object (not the config file)
|
126
136
|
# By adding a Hash, you create a new group
|
127
|
-
def add(param_name, value)
|
137
|
+
def add(param_name, value, override = false)
|
128
138
|
if value.class == Hash
|
129
139
|
if self.params.has_key?(param_name)
|
130
140
|
if self.params[param_name].class == Hash
|
131
|
-
|
141
|
+
if override
|
142
|
+
self.params[param_name] = value
|
143
|
+
else
|
144
|
+
self.params[param_name].merge!(value)
|
145
|
+
end
|
132
146
|
elsif self.params.has_key?(param_name)
|
133
147
|
if self.params[param_name].class != value.class
|
134
148
|
raise ArgumentError, "#{param_name} already exists, and is of different type!"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parseconfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BJ Dierkes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ParseConfig provides simple parsing of standard configuration files in
|
14
14
|
the form of 'param = value'. It also supports nested [group] sections.
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.4.1
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Config File Parser for Standard Unix/Linux Type Config Files
|