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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f73bde177ede4ff9e18afef840427c05f50f512
4
- data.tar.gz: bbc9fc38003b7353d28137deeaf719990eb8c53a
3
+ metadata.gz: 864866cc70755161288c70c089cd5155a14788a2
4
+ data.tar.gz: 6805636bed0bbe910383b8ca1a3df495b6f91a35
5
5
  SHA512:
6
- metadata.gz: 5173c739f0c6c9a368238791f642850be2991d4ef74b78eec967a835fd33027b67842d6897940b5f7f3961d37045b88a9fcc0e3c3cd3f087ff321a54e236c4c7
7
- data.tar.gz: 94f98c030682cce256543d6dc93647afec109edd5db1868437bfe7a13958d3a547d266831b87fd521a9c48e3f37d2199045e8ae635913ba682077b9fe8cb6a6e
6
+ metadata.gz: 2b1e073bb766a8a3d205b41e2258e8f1a8b565c94655c67c4a2ff09c36ba985a3cc796fdea5306d57cda63e3d65a0575990e3716273036e8ff9247c990b9fb97
7
+ data.tar.gz: fc8c076ad57a877f95694cf304aaf217bc264dc3ce6f115046bd5408b5ba1641657a0c731f17e69287c26847e9352746b46ce94f6fd360ae95281865a33a7319
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- collapsium-config (0.4.1)
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.1)
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. ... after each item, the items it itself extends are added before the next
194
- item is processed.
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
@@ -9,6 +9,6 @@
9
9
  module Collapsium
10
10
  module Config
11
11
  # The current release version
12
- VERSION = "0.4.1".freeze
12
+ VERSION = "0.4.2".freeze
13
13
  end # module Config
14
14
  end # module Collapsium
@@ -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
- it "extends configuration hashes" do
100
- config = File.join(@data_path, 'driverconfig.yml')
101
- cfg = Collapsium::Config::Configuration.load_config(config)
102
-
103
- # First, test for non-extended values
104
- expect(cfg["drivers.mock.mockoption"]).to eql 42
105
- expect(cfg["drivers.branch1.branch1option"]).to eql "foo"
106
- expect(cfg["drivers.branch2.branch2option"]).to eql "bar"
107
- expect(cfg["drivers.branch3.branch3option"]).to eql "baz"
108
- expect(cfg["drivers.leaf.leafoption"]).to eql "baz"
109
-
110
- # Now test extended values
111
- expect(cfg["drivers.branch1.mockoption"]).to eql 42
112
- expect(cfg["drivers.branch2.mockoption"]).to eql 42
113
- expect(cfg["drivers.leaf.mockoption"]).to eql 42
114
-
115
- expect(cfg["drivers.branch2.branch1option"]).to eql "foo"
116
- expect(cfg["drivers.leaf.branch1option"]).to eql "override" # not "foo" !
117
-
118
- expect(cfg["drivers.leaf.branch2option"]).to eql "bar"
119
- expect(cfg["drivers.leaf.global_opt"]).to eql "set"
120
-
121
- expect(cfg["drivers.branch3.global_opt"]).to eql "set"
122
-
123
- # Also test that all levels go back to base == mock
124
- expect(cfg["drivers.branch1.base"]).to eql %w(.drivers.mock)
125
- expect(cfg["drivers.branch2.base"]).to eql %w(.drivers.mock .drivers.branch1)
126
- expect(cfg["drivers.branch3.base"]).to eql %w(.global)
127
- expect(cfg["drivers.leaf.base"]).to eql %w(.drivers.mock .drivers.branch1
128
- .drivers.branch2 .global)
129
-
130
- # We expect that 'derived' is extended with '.other.base', too
131
- expect(cfg["derived.test.foo"]).to eql 'bar'
132
- expect(cfg["derived.test.some"]).to eql 'option'
133
-
134
- # Expect this to also work with list items
135
- expect(cfg["derived.test2.0.foo"]).to eql 'bar'
136
- expect(cfg["derived.test2.0.some"]).to eql 'option'
137
-
138
- expect(cfg["derived.test3.foo"]).to eql 'bar'
139
- expect(cfg["derived.test3.some2"]).to eql 'option2'
140
-
141
- # Expect this to work with multiple inheritance
142
- expect(cfg["derived.test4.foo"]).to eql 'bar'
143
- expect(cfg["derived.test4.some"]).to eql 'option_override'
144
- expect(cfg["derived.test4.some2"]).to eql 'option2'
145
- end
146
-
147
- it "extends configuration hashes when the base does not exist" do
148
- config = File.join(@data_path, 'driverconfig.yml')
149
- cfg = Collapsium::Config::Configuration.load_config(config)
150
-
151
- # Ensure the hash contains its own value
152
- expect(cfg["drivers.base_does_not_exist.some"]).to eql "value"
153
-
154
- # Also ensure the "base" is _not_ set properly
155
- expect(cfg["drivers.base_does_not_exist.base"]).to be_nil
156
-
157
- # On the other hand, "extends" should stay.
158
- expect(cfg["drivers.base_does_not_exist.extends"]).to eql "nonexistent_base"
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
@@ -26,6 +26,10 @@ drivers:
26
26
  extends: branch2,.global
27
27
  leafoption: baz
28
28
  branch1option: override
29
+ leaf2:
30
+ extends: .global, branch2
31
+ leafoption: baz
32
+ branch1option: override
29
33
  base_does_not_exist:
30
34
  extends: nonexistent_base
31
35
  some: value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collapsium-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Finkhaeuser