configru 0.0.1 → 0.0.2
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.
- data/lib/configru/confighash.rb +2 -0
- data/lib/configru/dsl.rb +1 -1
- data/lib/configru/version.rb +1 -1
- data/test/confighash_test.rb +10 -0
- data/test/hashdsl_test.rb +41 -0
- metadata +5 -3
data/lib/configru/confighash.rb
CHANGED
@@ -19,6 +19,8 @@ module Configru
|
|
19
19
|
|
20
20
|
def [](key)
|
21
21
|
key = key.to_s if key.is_a?(Symbol)
|
22
|
+
# Allow for accessing keys with hypens using underscores
|
23
|
+
key = key.gsub('_', '-')
|
22
24
|
# For some reason, super(key) returns {} instead of nil when the key
|
23
25
|
# doesn't exist :\
|
24
26
|
super(key) if self.include?(key)
|
data/lib/configru/dsl.rb
CHANGED
data/lib/configru/version.rb
CHANGED
data/test/confighash_test.rb
CHANGED
@@ -50,4 +50,14 @@ context 'ConfigHash - ' do
|
|
50
50
|
asserts('baz.apple') { topic.baz.apple }.equals(6)
|
51
51
|
asserts('baz.quux') { topic.baz.quux }.equals(5)
|
52
52
|
end
|
53
|
+
|
54
|
+
context 'keys with hyphens' do
|
55
|
+
hookup do
|
56
|
+
topic.merge!({'foo-bar-baz' => 1})
|
57
|
+
end
|
58
|
+
|
59
|
+
asserts('foo_bar_baz') { topic.foo_bar_baz }.equals(1)
|
60
|
+
asserts('[:foo_bar_baz]') { topic[:foo_bar_baz] }.equals(1)
|
61
|
+
asserts("['foo_bar_baz']") { topic['foo_bar_baz'] }.equals(1)
|
62
|
+
end
|
53
63
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
require 'configru/dsl'
|
3
|
+
|
4
|
+
context 'HashDSL - flat' do
|
5
|
+
setup do
|
6
|
+
block = proc do
|
7
|
+
foo 1
|
8
|
+
bar 2
|
9
|
+
end
|
10
|
+
Configru::DSL::HashDSL.new(block).hash
|
11
|
+
end
|
12
|
+
|
13
|
+
asserts_topic.equals({'foo' => 1, 'bar' => 2})
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'HashDSL - nested' do
|
17
|
+
setup do
|
18
|
+
block = proc do
|
19
|
+
foo 1
|
20
|
+
bar do
|
21
|
+
baz 2
|
22
|
+
quux 3
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Configru::DSL::HashDSL.new(block).hash
|
26
|
+
end
|
27
|
+
|
28
|
+
asserts_topic.equals({'foo' => 1, 'bar' => {'baz' => 2, 'quux' => 3}})
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'HashDSL - keys with underscores' do
|
32
|
+
setup do
|
33
|
+
block = proc do
|
34
|
+
foo_bar 1
|
35
|
+
baz_quux 2
|
36
|
+
end
|
37
|
+
Configru::DSL::HashDSL.new(block).hash
|
38
|
+
end
|
39
|
+
|
40
|
+
asserts_topic.equals({'foo-bar' => 1, 'baz-quux' => 2})
|
41
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Curtis McEnroe
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/configru/dsl.rb
|
39
39
|
- lib/configru/version.rb
|
40
40
|
- test/confighash_test.rb
|
41
|
+
- test/hashdsl_test.rb
|
41
42
|
- test/teststrap.rb
|
42
43
|
has_rdoc: true
|
43
44
|
homepage: https://github.com/programble/configru
|
@@ -73,4 +74,5 @@ specification_version: 3
|
|
73
74
|
summary: Versatile configuration file loader
|
74
75
|
test_files:
|
75
76
|
- test/confighash_test.rb
|
77
|
+
- test/hashdsl_test.rb
|
76
78
|
- test/teststrap.rb
|