collapsium-config 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/collapsium-config/configuration.rb +6 -10
- data/lib/collapsium-config/version.rb +1 -1
- data/spec/configuration_spec.rb +115 -61
- data/spec/data/driverconfig.yml +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 864866cc70755161288c70c089cd5155a14788a2
|
4
|
+
data.tar.gz: 6805636bed0bbe910383b8ca1a3df495b6f91a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b1e073bb766a8a3d205b41e2258e8f1a8b565c94655c67c4a2ff09c36ba985a3cc796fdea5306d57cda63e3d65a0575990e3716273036e8ff9247c990b9fb97
|
7
|
+
data.tar.gz: fc8c076ad57a877f95694cf304aaf217bc264dc3ce6f115046bd5408b5ba1641657a0c731f17e69287c26847e9352746b46ce94f6fd360ae95281865a33a7319
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
collapsium-config (0.4.
|
4
|
+
collapsium-config (0.4.2)
|
5
5
|
collapsium (~> 0.6)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.3.0)
|
11
|
-
codeclimate-test-reporter (1.0.
|
11
|
+
codeclimate-test-reporter (1.0.2)
|
12
12
|
collapsium (0.6.1)
|
13
13
|
diff-lcs (1.2.5)
|
14
14
|
docile (1.1.5)
|
data/README.md
CHANGED
@@ -190,8 +190,8 @@ bases merged into the value.
|
|
190
190
|
- Multiple levels of extension are supported.
|
191
191
|
- The order of items in `base` is deterministic:
|
192
192
|
1. Items are added in the order in which they appear in `extends`, but...
|
193
|
-
1. ...
|
194
|
-
item is
|
193
|
+
1. ... before each item, it's ancestors are listed in depth-first order,
|
194
|
+
which means the root of each item's hierarchy is listed first.
|
195
195
|
|
196
196
|
### Includes
|
197
197
|
|
@@ -337,20 +337,16 @@ module Collapsium
|
|
337
337
|
bases.each do |base_path, base_value|
|
338
338
|
base_value.recursive_resolve(root, base_path)
|
339
339
|
merged_base.recursive_merge!(base_value, true)
|
340
|
+
|
341
|
+
# Modify bases for this path: we go depth first into the hierarchy
|
342
|
+
base_val = merged_base.fetch("base", []).dup
|
343
|
+
base_val << base_path
|
344
|
+
base_val.uniq!
|
345
|
+
merged_base["base"] = base_val
|
340
346
|
end
|
341
347
|
|
342
348
|
# ... but value needs to stay authoritative.
|
343
349
|
value.recursive_merge!(merged_base, false)
|
344
|
-
|
345
|
-
# Set the base if all is well.
|
346
|
-
base_val = value["base"] || []
|
347
|
-
base_val += bases.map { |p, _| p }
|
348
|
-
base_val.uniq!
|
349
|
-
if base_val.empty?
|
350
|
-
return
|
351
|
-
end
|
352
|
-
|
353
|
-
value["base"] = base_val
|
354
350
|
end
|
355
351
|
end # class Configuration
|
356
352
|
end # module Config
|
data/spec/configuration_spec.rb
CHANGED
@@ -2,8 +2,11 @@ require 'spec_helper'
|
|
2
2
|
require_relative '../lib/collapsium-config/configuration'
|
3
3
|
|
4
4
|
describe Collapsium::Config::Configuration do
|
5
|
-
before do
|
5
|
+
before(:all) do
|
6
6
|
@data_path = File.join(File.dirname(__FILE__), 'data')
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
7
10
|
ENV.delete("BAZ")
|
8
11
|
end
|
9
12
|
|
@@ -96,66 +99,117 @@ describe Collapsium::Config::Configuration do
|
|
96
99
|
end
|
97
100
|
|
98
101
|
describe "extend functionality" do
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
102
|
+
context "merging" do
|
103
|
+
before(:all) do
|
104
|
+
@config_path = File.join(@data_path, 'driverconfig.yml')
|
105
|
+
@config = Collapsium::Config::Configuration.load_config(@config_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
context "drivers" do
|
109
|
+
it "accepts mock drivers" do
|
110
|
+
# There is no built-in driver labelled 'mock'
|
111
|
+
expect(@config["drivers.mock.mockoption"]).to eql 42
|
112
|
+
end
|
113
|
+
|
114
|
+
it "merges a single ancestor" do
|
115
|
+
# Check merged values
|
116
|
+
expect(@config["drivers.branch1.branch1option"]).to eql "foo"
|
117
|
+
expect(@config["drivers.branch1.mockoption"]).to eql 42
|
118
|
+
|
119
|
+
# Check merge metadata
|
120
|
+
expect(@config["drivers.branch1.extends"]).to be_nil
|
121
|
+
expect(@config["drivers.branch1.base"]).to eql %w(.drivers.mock)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "merges multiple ancestor depths" do
|
125
|
+
# Check merged values
|
126
|
+
expect(@config["drivers.branch2.branch2option"]).to eql "bar"
|
127
|
+
expect(@config["drivers.branch2.branch1option"]).to eql "foo"
|
128
|
+
expect(@config["drivers.branch2.mockoption"]).to eql 42
|
129
|
+
|
130
|
+
# Check merge metadata
|
131
|
+
expect(@config["drivers.branch2.extends"]).to be_nil
|
132
|
+
expect(@config["drivers.branch2.base"]).to eql %w(.drivers.mock
|
133
|
+
.drivers.branch1)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "merges from absolute paths" do
|
137
|
+
# Check merged values
|
138
|
+
expect(@config["drivers.branch3.branch3option"]).to eql "baz"
|
139
|
+
expect(@config["drivers.branch3.global_opt"]).to eql "set"
|
140
|
+
|
141
|
+
# Check merge metadata
|
142
|
+
expect(@config["drivers.branch3.extends"]).to be_nil
|
143
|
+
expect(@config["drivers.branch3.base"]).to eql %w(.global)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "merges from sibling and absolute path" do
|
147
|
+
# Check merged values
|
148
|
+
expect(@config["drivers.leaf.leafoption"]).to eql "baz"
|
149
|
+
expect(@config["drivers.leaf.branch2option"]).to eql "bar"
|
150
|
+
expect(@config["drivers.leaf.branch1option"]).to eql "override"
|
151
|
+
expect(@config["drivers.leaf.mockoption"]).to eql 42
|
152
|
+
expect(@config["drivers.leaf.global_opt"]).to eql "set"
|
153
|
+
|
154
|
+
# Check merge metadata
|
155
|
+
expect(@config["drivers.leaf.extends"]).to be_nil
|
156
|
+
expect(@config["drivers.leaf.base"]).to eql %w(.drivers.mock
|
157
|
+
.drivers.branch1
|
158
|
+
.drivers.branch2
|
159
|
+
.global)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "merges from global and absolute path" do
|
163
|
+
# Check merged values
|
164
|
+
expect(@config["drivers.leaf2.leafoption"]).to eql "baz"
|
165
|
+
expect(@config["drivers.leaf2.global_opt"]).to eql "set"
|
166
|
+
expect(@config["drivers.leaf2.branch2option"]).to eql "bar"
|
167
|
+
expect(@config["drivers.leaf2.branch1option"]).to eql "override"
|
168
|
+
expect(@config["drivers.leaf2.mockoption"]).to eql 42
|
169
|
+
|
170
|
+
# Check merge metadata
|
171
|
+
expect(@config["drivers.leaf2.extends"]).to be_nil
|
172
|
+
expect(@config["drivers.leaf2.base"]).to eql %w(.global
|
173
|
+
.drivers.mock
|
174
|
+
.drivers.branch1
|
175
|
+
.drivers.branch2)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "works when a base does not exist" do
|
179
|
+
# Ensure the hash contains its own value
|
180
|
+
expect(@config["drivers.base_does_not_exist.some"]).to eql "value"
|
181
|
+
|
182
|
+
# Also ensure the "base" is _not_ set properly
|
183
|
+
expect(@config["drivers.base_does_not_exist.base"]).to be_nil
|
184
|
+
|
185
|
+
# On the other hand, "extends" should stay.
|
186
|
+
expect(@config["drivers.base_does_not_exist.extends"]).to eql \
|
187
|
+
"nonexistent_base"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context "non-driver values" do
|
192
|
+
it "merges from absolute paths" do
|
193
|
+
expect(@config["derived.test.foo"]).to eql 'bar'
|
194
|
+
expect(@config["derived.test.some"]).to eql 'option'
|
195
|
+
end
|
196
|
+
|
197
|
+
it "can merge into list items" do
|
198
|
+
expect(@config["derived.test2.0.foo"]).to eql 'bar'
|
199
|
+
expect(@config["derived.test2.0.some"]).to eql 'option'
|
200
|
+
end
|
201
|
+
|
202
|
+
it "can merge from list items" do
|
203
|
+
expect(@config["derived.test3.foo"]).to eql 'bar'
|
204
|
+
expect(@config["derived.test3.some2"]).to eql 'option2'
|
205
|
+
end
|
206
|
+
|
207
|
+
it "accepts multiple extensions" do
|
208
|
+
expect(@config["derived.test4.foo"]).to eql 'bar'
|
209
|
+
expect(@config["derived.test4.some"]).to eql 'option_override'
|
210
|
+
expect(@config["derived.test4.some2"]).to eql 'option2'
|
211
|
+
end
|
212
|
+
end
|
159
213
|
end
|
160
214
|
|
161
215
|
it "does nothing when a hash extends itself" do
|
data/spec/data/driverconfig.yml
CHANGED