configparser 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configparser.rb +8 -4
- data/lib/configparser/version.rb +1 -1
- data/test/test_configparser.rb +18 -4
- 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: 42a4613bc96b535efac8c96b423eb3990946876c
|
4
|
+
data.tar.gz: ca2ee55f792fcde58014508cbc5ed23bedb9476e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d3d5f30257627c7e91e1ec1df2a522ce90c5a450afcb4bb62fba1549d16f7737c6de202de1b3d0e08d416585ecbe775214def93a5fce1bdf52138249a101c56
|
7
|
+
data.tar.gz: ced3899217c2d2252824145acb1be8b7ad153fc9135465f1c39b4a3e20d40314b9f55a26fd72d8f6e4b71f007ee96bb3c44e0b52a685e86104d555bd43c28df4
|
data/lib/configparser.rb
CHANGED
@@ -14,7 +14,7 @@ class ConfigParser < Hash
|
|
14
14
|
next if (line =~ /^\s*(#|;)/)
|
15
15
|
|
16
16
|
# parse out the lines of the config
|
17
|
-
if line =~ /^\s*(.+?)\s*[=:]\s*(
|
17
|
+
if line =~ /^\s*(.+?)\s*[=:]\s*(.*)$/ # handle key=value lines
|
18
18
|
if section
|
19
19
|
self[section] = {} unless self[section]
|
20
20
|
key = $1
|
@@ -74,15 +74,17 @@ class ConfigParser < Hash
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def to_s
|
77
|
+
def to_s(sep=':')
|
78
78
|
str = ""
|
79
79
|
# print globals first
|
80
80
|
self.keys.sort.each do |k|
|
81
81
|
next if self[k].is_a? Hash
|
82
82
|
if self[k] === true
|
83
83
|
str << "#{k}\n"
|
84
|
+
elsif self[k] == ""
|
85
|
+
str << "#{k}#{sep}\n"
|
84
86
|
else
|
85
|
-
str << "#{k}
|
87
|
+
str << "#{k}#{sep} #{self[k]}\n"
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -93,8 +95,10 @@ class ConfigParser < Hash
|
|
93
95
|
self[k].keys.sort.each do |j|
|
94
96
|
if self[k][j] === true
|
95
97
|
str << "#{j}\n"
|
98
|
+
elsif self[k][j] == ""
|
99
|
+
str << "#{j}#{sep}\n"
|
96
100
|
else
|
97
|
-
str << "#{j}
|
101
|
+
str << "#{j}#{sep} #{self[k][j]}\n"
|
98
102
|
end
|
99
103
|
end
|
100
104
|
end
|
data/lib/configparser/version.rb
CHANGED
data/test/test_configparser.rb
CHANGED
@@ -31,7 +31,7 @@ yourtest: 99
|
|
31
31
|
[second section]
|
32
32
|
myway: or the highway
|
33
33
|
"
|
34
|
-
assert_equal(doc,cp.to_s)
|
34
|
+
assert_equal(doc, cp.to_s)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_parse_a_config_with_substitutions
|
@@ -69,7 +69,7 @@ end_of_simple
|
|
69
69
|
|
70
70
|
cp = ConfigParser.new()
|
71
71
|
cp.parse(simple_content.each_line)
|
72
|
-
assert_equal(
|
72
|
+
assert_equal({
|
73
73
|
"test1" => "hi",
|
74
74
|
"test2" => "hello",
|
75
75
|
"first_section" => {
|
@@ -79,7 +79,7 @@ end_of_simple
|
|
79
79
|
},
|
80
80
|
"second section" => {
|
81
81
|
"myway" => "or the highway"
|
82
|
-
}})
|
82
|
+
}}, cp)
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_parse_configparser_example_from_python
|
@@ -94,6 +94,7 @@ values like this: 1000000
|
|
94
94
|
[Multiline Values]
|
95
95
|
chorus: I'm a lumberjack, and I'm okay I sleep all night and I work all day
|
96
96
|
[No Values]
|
97
|
+
empty string value here:
|
97
98
|
key_without_value
|
98
99
|
[Sections Can Be Indented]
|
99
100
|
can_values_be_as_well: True
|
@@ -110,5 +111,18 @@ you can also use: to delimit keys from values
|
|
110
111
|
|
111
112
|
assert_equal(doc, cp.to_s)
|
112
113
|
end
|
113
|
-
|
114
|
+
|
115
|
+
def test_nil_option
|
116
|
+
nil_content = <<end_of_simple
|
117
|
+
[some_section]
|
118
|
+
foo=
|
119
|
+
end_of_simple
|
120
|
+
cp = ConfigParser.new()
|
121
|
+
cp.parse(nil_content.each_line)
|
122
|
+
assert_equal({
|
123
|
+
"some_section" => {
|
124
|
+
"foo" => ""
|
125
|
+
}}, cp)
|
126
|
+
assert_equal(nil_content, cp.to_s("="))
|
127
|
+
end
|
114
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrislee35
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.4.6
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: parses configuration files compatable with Python's ConfigParser
|