centroid 1.1.0.pre.alpha1 → 1.1.0.pre.alpha2
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/centroid.gemspec +1 -1
- data/lib/centroid.rb +12 -0
- data/test/centroid_test.rb +38 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df795b772134e8a324de1458de777abbc9cc536c
|
4
|
+
data.tar.gz: fec9de1bb2c4d766dfcf96e8333acf12047f82f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c56b4ea74fd10f1258a294c2eca63edcb1b8ae568888ead7c97691901727cd56ed4b7047dd5a6d0e8f9504c573f8fead691139c23b3f3290bfdb143c7074e52
|
7
|
+
data.tar.gz: 300a1aa16b2c8aa7fa8b6c5170206b31e584cf1a3a3dcfe6eea6f427bfe340b618f69e4edfb7e4a6319d7c44c0b48d7f3975a94648cfe06d844aa4c8f3964794
|
data/centroid.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'centroid'
|
3
|
-
s.version = '1.1.0-
|
3
|
+
s.version = '1.1.0-alpha2'
|
4
4
|
s.summary = 'A centralizaed paradigm to configuration management.'
|
5
5
|
s.description = 'Centroid is a tool for loading configuration values declared in JSON, and accessing those configuration values using object properties.'
|
6
6
|
s.author = 'Resource Data, Inc'
|
data/lib/centroid.rb
CHANGED
@@ -21,6 +21,18 @@ module Centroid
|
|
21
21
|
has_key?(method_name)
|
22
22
|
end
|
23
23
|
|
24
|
+
def each
|
25
|
+
return enum_for :each unless block_given?
|
26
|
+
|
27
|
+
raw_config.each do |key, value|
|
28
|
+
if value.is_a?(Hash)
|
29
|
+
yield key, Config.new(value)
|
30
|
+
else
|
31
|
+
yield key, value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
24
36
|
def [](key)
|
25
37
|
raise KeyError.new("Centroid::Config instance does not contain key: #{key}") unless has_key?(key)
|
26
38
|
|
data/test/centroid_test.rb
CHANGED
@@ -4,7 +4,7 @@ require "json"
|
|
4
4
|
|
5
5
|
class ConfigTests < Test::Unit::TestCase
|
6
6
|
def json_config
|
7
|
-
'{"
|
7
|
+
'{"theEnvironment":{"theKey":"TheValue"}}'
|
8
8
|
end
|
9
9
|
|
10
10
|
def shared_file_path
|
@@ -13,7 +13,7 @@ class ConfigTests < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
def test_create_from_string
|
15
15
|
config = Centroid::Config.new(json_config)
|
16
|
-
assert_equal(config.
|
16
|
+
assert_equal(config.the_environment.the_key, "TheValue")
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_create_from_file
|
@@ -46,12 +46,12 @@ class ConfigTests < Test::Unit::TestCase
|
|
46
46
|
|
47
47
|
def test_readable_using_snake_case_property
|
48
48
|
config = Centroid::Config.new(json_config)
|
49
|
-
assert_equal(config.
|
49
|
+
assert_equal(config.the_environment.the_key, "TheValue")
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_environment_specific_config_is_included
|
53
53
|
config = Centroid::Config.new(json_config)
|
54
|
-
environment_config = config.for_environment("
|
54
|
+
environment_config = config.for_environment("theEnvironment")
|
55
55
|
assert_equal(environment_config.the_key, "TheValue")
|
56
56
|
end
|
57
57
|
|
@@ -75,8 +75,8 @@ class ConfigTests < Test::Unit::TestCase
|
|
75
75
|
|
76
76
|
def test_modifying_raw_config
|
77
77
|
config = Centroid::Config.new(json_config)
|
78
|
-
config.raw_config["
|
79
|
-
assert_equal(config.
|
78
|
+
config.raw_config["theEnvironment"]["theKey"] = "NotTheValue"
|
79
|
+
assert_equal(config.the_environment.the_key, "NotTheValue")
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_environment_specific_config_overrides_all
|
@@ -104,13 +104,43 @@ class ConfigTests < Test::Unit::TestCase
|
|
104
104
|
|
105
105
|
def test_has_key
|
106
106
|
config = Centroid::Config.new(json_config)
|
107
|
-
assert(config.has_key?("
|
107
|
+
assert(config.has_key?("the_environment"))
|
108
108
|
assert(!config.has_key?("does_not_exist"))
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_respond_to
|
112
112
|
config = Centroid::Config.new(json_config)
|
113
|
-
assert(config.respond_to?(:
|
113
|
+
assert(config.respond_to?(:the_environment))
|
114
114
|
assert(!config.respond_to?(:does_not_exist))
|
115
115
|
end
|
116
|
+
|
117
|
+
def test_enumerating_json_object
|
118
|
+
config = Centroid::Config.new(json_config)
|
119
|
+
itemCount = 0
|
120
|
+
config.each do |item|
|
121
|
+
itemCount += 1
|
122
|
+
end
|
123
|
+
assert_equal(itemCount, 1)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_enumerated_json_object_values_are_still_shiny
|
127
|
+
json = '
|
128
|
+
{
|
129
|
+
"connections": {
|
130
|
+
"firstConnection": {
|
131
|
+
"user": "firstUser",
|
132
|
+
"password":"secret"
|
133
|
+
},
|
134
|
+
"secondConnection": {
|
135
|
+
"user": "secondUser",
|
136
|
+
"password":"secret"
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}'
|
140
|
+
|
141
|
+
config = Centroid::Config.new(json)
|
142
|
+
config.connections.each do |k, v|
|
143
|
+
assert_equal(v.password, "secret")
|
144
|
+
end
|
145
|
+
end
|
116
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: centroid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.pre.
|
4
|
+
version: 1.1.0.pre.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Resource Data, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Centroid is a tool for loading configuration values declared in JSON,
|
14
14
|
and accessing those configuration values using object properties.
|