confset 1.0.0
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 +7 -0
- data/Rakefile +44 -0
- data/docs/CHANGELOG.md +15 -0
- data/docs/LICENSE.md +29 -0
- data/lib/confset/configuration.rb +37 -0
- data/lib/confset/integrations/heroku.rb +61 -0
- data/lib/confset/integrations/rails/railtie.rb +40 -0
- data/lib/confset/integrations/sinatra.rb +27 -0
- data/lib/confset/options.rb +187 -0
- data/lib/confset/rack/reloader.rb +17 -0
- data/lib/confset/sources/env_source.rb +74 -0
- data/lib/confset/sources/hash_source.rb +18 -0
- data/lib/confset/sources/yaml_source.rb +34 -0
- data/lib/confset/tasks/heroku.rake +9 -0
- data/lib/confset/validation/error.rb +13 -0
- data/lib/confset/validation/schema.rb +22 -0
- data/lib/confset/validation/validate.rb +26 -0
- data/lib/confset/version.rb +5 -0
- data/lib/confset.rb +89 -0
- data/lib/generators/confset/install_generator.rb +34 -0
- data/lib/generators/confset/templates/confset.rb +58 -0
- data/lib/generators/confset/templates/settings/development.yml +0 -0
- data/lib/generators/confset/templates/settings/production.yml +0 -0
- data/lib/generators/confset/templates/settings/test.yml +0 -0
- data/lib/generators/confset/templates/settings.local.yml +0 -0
- data/lib/generators/confset/templates/settings.yml +0 -0
- data/spec/config_env_spec.rb +238 -0
- data/spec/config_spec.rb +468 -0
- data/spec/configuration_spec.rb +16 -0
- data/spec/fixtures/bool_override/config1.yml +2 -0
- data/spec/fixtures/bool_override/config2.yml +2 -0
- data/spec/fixtures/custom_types/hash.yml +7 -0
- data/spec/fixtures/deep_merge/config1.yml +31 -0
- data/spec/fixtures/deep_merge/config2.yml +28 -0
- data/spec/fixtures/deep_merge2/config1.yml +3 -0
- data/spec/fixtures/deep_merge2/config2.yml +2 -0
- data/spec/fixtures/deep_merge3/config1.yml +1 -0
- data/spec/fixtures/deep_merge3/config2.yml +1 -0
- data/spec/fixtures/development.yml +4 -0
- data/spec/fixtures/empty1.yml +0 -0
- data/spec/fixtures/empty2.yml +0 -0
- data/spec/fixtures/knockout_prefix/config1.yml +40 -0
- data/spec/fixtures/knockout_prefix/config2.yml +28 -0
- data/spec/fixtures/knockout_prefix/config3.yml +14 -0
- data/spec/fixtures/malformed.yml +6 -0
- data/spec/fixtures/multilevel.yml +10 -0
- data/spec/fixtures/overwrite_arrays/config1.yml +17 -0
- data/spec/fixtures/overwrite_arrays/config2.yml +12 -0
- data/spec/fixtures/overwrite_arrays/config3.yml +10 -0
- data/spec/fixtures/reserved_keywords.yml +7 -0
- data/spec/fixtures/settings.yml +22 -0
- data/spec/fixtures/settings2.yml +1 -0
- data/spec/fixtures/unsafe_load.yml +12 -0
- data/spec/fixtures/validation/confset.yml +3 -0
- data/spec/fixtures/with_erb.yml +4 -0
- data/spec/fixtures/with_malformed_erb.yml +1 -0
- data/spec/options_spec.rb +255 -0
- data/spec/sources/env_source_spec.rb +81 -0
- data/spec/sources/hash_source_spec.rb +49 -0
- data/spec/sources/yaml_source_spec.rb +145 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/support/fixture_helper.rb +14 -0
- data/spec/support/rails_helper.rb +24 -0
- data/spec/support/shared_contexts/rake.rb +8 -0
- data/spec/validation_spec.rb +84 -0
- metadata +295 -0
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,468 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Confset do
|
6
|
+
before :each do
|
7
|
+
Confset.reset
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should get setting files" do
|
11
|
+
config = Confset.setting_files("root/config", "staging")
|
12
|
+
expect(config).to eq([
|
13
|
+
"root/config/settings.yml",
|
14
|
+
"root/config/settings/staging.yml",
|
15
|
+
"root/config/environments/staging.yml",
|
16
|
+
"root/config/settings.local.yml",
|
17
|
+
"root/config/settings/staging.local.yml",
|
18
|
+
"root/config/environments/staging.local.yml"
|
19
|
+
])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should ignore local config in test environment" do
|
23
|
+
config = Confset.setting_files("root/config", "test")
|
24
|
+
expect(config).to eq([
|
25
|
+
"root/config/settings.yml",
|
26
|
+
"root/config/settings/test.yml",
|
27
|
+
"root/config/environments/test.yml",
|
28
|
+
"root/config/settings/test.local.yml",
|
29
|
+
"root/config/environments/test.local.yml"
|
30
|
+
])
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should load a basic config file" do
|
34
|
+
config = Confset.load_files("spec/fixtures/settings.yml")
|
35
|
+
expect(config.size).to eq(1)
|
36
|
+
expect(config.server).to eq("google.com")
|
37
|
+
expect(config["1"]).to eq("one")
|
38
|
+
expect(config.photo_sizes.avatar).to eq([60, 60])
|
39
|
+
expect(config.root["yahoo.com"]).to eq(2)
|
40
|
+
expect(config.root["google.com"]).to eq(3)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should load 2 basic config files" do
|
44
|
+
config = Confset.load_files("spec/fixtures/settings.yml", "spec/fixtures/settings2.yml")
|
45
|
+
expect(config.size).to eq(1)
|
46
|
+
expect(config.server).to eq("google.com")
|
47
|
+
expect(config.another).to eq("something")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should load config files specified as Pathname objects" do
|
51
|
+
path = Pathname.new("spec/fixtures").join("settings.yml")
|
52
|
+
config = Confset.load_files(path)
|
53
|
+
expect(config.server).to eq("google.com")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should load config files specified as objects responding to :load" do
|
57
|
+
source = double "source"
|
58
|
+
allow(source).to receive(:load) do
|
59
|
+
{ "server" => "google.com" }
|
60
|
+
end
|
61
|
+
config = Confset.load_files(source)
|
62
|
+
expect(config.server).to eq("google.com")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should load config from HashSource" do
|
66
|
+
source = Confset::Sources::HashSource.new({ "server" => "google.com" })
|
67
|
+
config = Confset.load_files(source)
|
68
|
+
expect(config.server).to eq("google.com")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should load config from files and HashSource" do
|
72
|
+
file_source = "spec/fixtures/settings.yml"
|
73
|
+
hash_source = Confset::Sources::HashSource.new({ "size" => 12 })
|
74
|
+
config = Confset.load_files(file_source, hash_source)
|
75
|
+
expect(config.server).to eq("google.com")
|
76
|
+
expect(config.size).to eq(12)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should load empty config for a missing file path" do
|
80
|
+
config = Confset.load_files("spec/fixtures/some_file_that_doesnt_exist.yml")
|
81
|
+
expect(config).to be_empty
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should load an empty config for multiple missing file paths" do
|
85
|
+
files = ["spec/fixtures/doesnt_exist1.yml", "spec/fixtures/doesnt_exist2.yml"]
|
86
|
+
config = Confset.load_files(files)
|
87
|
+
expect(config).to be_empty
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should load empty config for an empty setting file" do
|
91
|
+
config = Confset.load_files("spec/fixtures/empty1.yml")
|
92
|
+
expect(config).to be_empty
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should convert to a hash" do
|
96
|
+
config = Confset.load_files("spec/fixtures/development.yml").to_hash
|
97
|
+
expect(config[:section][:servers]).to be_kind_of(Array)
|
98
|
+
expect(config[:section][:servers][0][:name]).to eq("yahoo.com")
|
99
|
+
expect(config[:section][:servers][1][:name]).to eq("amazon.com")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should convert to a hash (We Need To Go Deeper)" do
|
103
|
+
config = Confset.load_files("spec/fixtures/development.yml").to_hash
|
104
|
+
servers = config[:section][:servers]
|
105
|
+
expect(servers).to eq([{ name: "yahoo.com" }, { name: "amazon.com" }])
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should convert to a hash without modifying nested settings" do
|
109
|
+
config = Confset.load_files("spec/fixtures/development.yml")
|
110
|
+
config.to_hash
|
111
|
+
expect(config).to be_kind_of(Confset::Options)
|
112
|
+
expect(config[:section]).to be_kind_of(Confset::Options)
|
113
|
+
expect(config[:section][:servers][0]).to be_kind_of(Confset::Options)
|
114
|
+
expect(config[:section][:servers][1]).to be_kind_of(Confset::Options)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should convert to a hash without modifying nested settings" do
|
118
|
+
config = Confset.load_files("spec/fixtures/development.yml")
|
119
|
+
config.to_h
|
120
|
+
expect(config).to be_kind_of(Confset::Options)
|
121
|
+
expect(config[:section]).to be_kind_of(Confset::Options)
|
122
|
+
expect(config[:section][:servers][0]).to be_kind_of(Confset::Options)
|
123
|
+
expect(config[:section][:servers][1]).to be_kind_of(Confset::Options)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should convert to a json" do
|
127
|
+
config = Confset.load_files("spec/fixtures/development.yml").to_json
|
128
|
+
expect(JSON.parse(config)["section"]["servers"]).to be_kind_of(Array)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should load an empty config for multiple missing file paths" do
|
132
|
+
files = ["spec/fixtures/empty1.yml", "spec/fixtures/empty2.yml"]
|
133
|
+
config = Confset.load_files(files)
|
134
|
+
expect(config).to be_empty
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should allow overrides" do
|
138
|
+
files = ["spec/fixtures/settings.yml", "spec/fixtures/development.yml"]
|
139
|
+
config = Confset.load_files(files)
|
140
|
+
expect(config.server).to eq("google.com")
|
141
|
+
expect(config.size).to eq(2)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should allow full reload of the settings files" do
|
145
|
+
files = ["spec/fixtures/settings.yml"]
|
146
|
+
Confset.load_and_set_settings(files)
|
147
|
+
expect(Settings.server).to eq("google.com")
|
148
|
+
expect(Settings.size).to eq(1)
|
149
|
+
|
150
|
+
files = ["spec/fixtures/settings.yml", "spec/fixtures/development.yml"]
|
151
|
+
Settings.reload_from_files(files)
|
152
|
+
expect(Settings.server).to eq("google.com")
|
153
|
+
expect(Settings.size).to eq(2)
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
context "Nested Settings" do
|
159
|
+
let(:config) do
|
160
|
+
Confset.load_files("spec/fixtures/development.yml")
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should allow nested sections" do
|
164
|
+
expect(config.section.size).to eq(3)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should allow configuration collections (arrays)" do
|
168
|
+
expect(config.section.servers[0].name).to eq("yahoo.com")
|
169
|
+
expect(config.section.servers[1].name).to eq("amazon.com")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context "Settings with ERB tags" do
|
174
|
+
let(:config) do
|
175
|
+
Confset.load_files("spec/fixtures/with_erb.yml")
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should evaluate ERB tags" do
|
179
|
+
expect(config.computed).to eq(6)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should evaluated nested ERB tags" do
|
183
|
+
expect(config.section.computed1).to eq(1)
|
184
|
+
expect(config.section.computed2).to eq(2)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
context "Boolean Overrides" do
|
190
|
+
let(:config) do
|
191
|
+
files = ["spec/fixtures/bool_override/config1.yml", "spec/fixtures/bool_override/config2.yml"]
|
192
|
+
Confset.load_files(files)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should allow overriding of bool settings" do
|
196
|
+
expect(config.override_bool).to eq(false)
|
197
|
+
expect(config.override_bool_opposite).to eq(true)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "Custom Configuration" do
|
202
|
+
it "should have the default settings constant as 'Settings'" do
|
203
|
+
expect(Confset.const_name).to eq("Settings")
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should be able to assign a different settings constant" do
|
207
|
+
Confset.setup { |config| config.const_name = "Settings2" }
|
208
|
+
|
209
|
+
expect(Confset.const_name).to eq("Settings2")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "Settings with a type value of 'hash'" do
|
214
|
+
let(:config) do
|
215
|
+
files = ["spec/fixtures/custom_types/hash.yml"]
|
216
|
+
Confset.load_files(files)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should turn that setting into a Real Hash" do
|
220
|
+
expect(config.prices).to be_kind_of(Hash)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should map the hash values correctly" do
|
224
|
+
expect(config.prices[1]).to eq(2.99)
|
225
|
+
expect(config.prices[5]).to eq(9.99)
|
226
|
+
expect(config.prices[15]).to eq(19.99)
|
227
|
+
expect(config.prices[30]).to eq(29.99)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "Merging hash at runtime" do
|
232
|
+
let(:config) { Confset.load_files("spec/fixtures/settings.yml") }
|
233
|
+
let(:hash) { { :options => { :suboption => "value" }, :server => "amazon.com" } }
|
234
|
+
|
235
|
+
it "should be chainable" do
|
236
|
+
expect(config.merge!({})).to eq(config)
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should preserve existing keys" do
|
240
|
+
expect { config.merge!({}) }.to_not change { config.keys }
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should recursively merge keys" do
|
244
|
+
config.merge!(hash)
|
245
|
+
expect(config.options.suboption).to eq("value")
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should rewrite a merged value" do
|
249
|
+
expect { config.merge!(hash) }.to change { config.server }.from("google.com").to("amazon.com")
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context "Merging nested hash at runtime" do
|
254
|
+
let(:config) { Confset.load_files("spec/fixtures/deep_merge/config1.yml") }
|
255
|
+
let(:hash) { { inner: { something1: "changed1", something3: "changed3" } } }
|
256
|
+
let(:hash_with_nil) { { inner: { something1: nil } } }
|
257
|
+
|
258
|
+
it "should preserve first level keys" do
|
259
|
+
expect { config.merge!(hash) }.to_not change { config.keys }
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should preserve nested key" do
|
263
|
+
config.merge!(hash)
|
264
|
+
expect(config.inner.something2).to eq("blah2")
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should add new nested key" do
|
268
|
+
expect { config.merge!(hash) }
|
269
|
+
.to change { config.inner.something3 }.from(nil).to("changed3")
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should rewrite a merged value" do
|
273
|
+
expect { config.merge!(hash) }
|
274
|
+
.to change { config.inner.something1 }.from("blah1").to("changed1")
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should update a string to nil " do
|
278
|
+
expect { config.merge!(hash_with_nil) }
|
279
|
+
.to change { config.inner.something1 }.from("blah1").to(nil)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should update something nil to true" do
|
283
|
+
expect { config.merge!(inner: { somethingnil: true }) }
|
284
|
+
.to change { config.inner.somethingnil }.from(nil).to(true)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should update something nil to false" do
|
288
|
+
expect { config.merge!(inner: { somethingnil: false }) }
|
289
|
+
.to change { config.inner.somethingnil }.from(nil).to(false)
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should update something false to true" do
|
293
|
+
expect { config.merge!(inner: { somethingfalse: true }) }
|
294
|
+
.to change { config.inner.somethingfalse }.from(false).to(true)
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should update something false to nil" do
|
298
|
+
expect { config.merge!(inner: { somethingfalse: nil }) }
|
299
|
+
.to change { config.inner.somethingfalse }.from(false).to(nil)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should update something true to false" do
|
303
|
+
expect { config.merge!(inner: { somethingtrue: false }) }
|
304
|
+
.to change { config.inner.somethingtrue }.from(true).to(false)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should update something true to nil" do
|
308
|
+
expect { config.merge!(inner: { somethingtrue: nil }) }
|
309
|
+
.to change { config.inner.somethingtrue }.from(true).to(nil)
|
310
|
+
end
|
311
|
+
|
312
|
+
context "with Confset.merge_nil_values = false" do
|
313
|
+
let(:config) do
|
314
|
+
Confset.merge_nil_values = false
|
315
|
+
Confset.load_files("spec/fixtures/deep_merge/config1.yml")
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should not overwrite values with nil" do
|
319
|
+
old_value = config.inner.something1
|
320
|
+
config.merge!(hash_with_nil)
|
321
|
+
expect(config.inner.something1).to eq(old_value)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context "[] accessors" do
|
327
|
+
let(:config) do
|
328
|
+
files = ["spec/fixtures/development.yml"]
|
329
|
+
Confset.load_files(files)
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should access attributes using []" do
|
333
|
+
expect(config.section["size"]).to eq(3)
|
334
|
+
expect(config.section[:size]).to eq(3)
|
335
|
+
expect(config[:section][:size]).to eq(3)
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should set values using []=" do
|
339
|
+
config.section[:foo] = "bar"
|
340
|
+
expect(config.section.foo).to eq("bar")
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context "enumerable" do
|
345
|
+
let(:config) do
|
346
|
+
files = ["spec/fixtures/development.yml"]
|
347
|
+
Confset.load_files(files)
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should enumerate top level parameters" do
|
351
|
+
keys = []
|
352
|
+
config.each { |key, value| keys << key }
|
353
|
+
expect(keys).to eq([:size, :section])
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should enumerate inner parameters" do
|
357
|
+
keys = []
|
358
|
+
config.section.each { |key, value| keys << key }
|
359
|
+
expect(keys).to eq([:size, :servers])
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should have methods defined by Enumerable" do
|
363
|
+
expect(config.map { |key, value| key }).to eq([:size, :section])
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
context "keys" do
|
368
|
+
let(:config) do
|
369
|
+
files = ["spec/fixtures/development.yml"]
|
370
|
+
Confset.load_files(files)
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should return array of keys" do
|
374
|
+
expect(config.keys).to contain_exactly(:size, :section)
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should return array of keys for nested entry" do
|
378
|
+
expect(config.section.keys).to contain_exactly(:size, :servers)
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
context "when loading settings files" do
|
383
|
+
context "using knockout_prefix" do
|
384
|
+
context "in configuration phase" do
|
385
|
+
it "should be able to assign a different knockout_prefix value" do
|
386
|
+
Confset.knockout_prefix = "--"
|
387
|
+
|
388
|
+
expect(Confset.knockout_prefix).to eq("--")
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should have the default knockout_prefix value equal nil" do
|
392
|
+
expect(Confset.knockout_prefix).to eq(nil)
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
context "merging" do
|
397
|
+
let(:config) do
|
398
|
+
Confset.knockout_prefix = "--"
|
399
|
+
Confset.overwrite_arrays = false
|
400
|
+
Confset.load_files(["spec/fixtures/knockout_prefix/config1.yml",
|
401
|
+
"spec/fixtures/knockout_prefix/config2.yml",
|
402
|
+
"spec/fixtures/knockout_prefix/config3.yml"])
|
403
|
+
end
|
404
|
+
|
405
|
+
it "should remove elements from settings" do
|
406
|
+
expect(config.array1).to eq(["item4", "item5", "item6"])
|
407
|
+
expect(config.array2.inner).to eq(["item4", "item5", "item6"])
|
408
|
+
expect(config.array3).to eq("")
|
409
|
+
expect(config.string1).to eq("")
|
410
|
+
expect(config.string2).to eq("")
|
411
|
+
expect(config.hash1.to_hash).to eq({ key1: "", key2: "", key3: "value3" })
|
412
|
+
expect(config.hash2).to eq("")
|
413
|
+
expect(config.hash3.to_hash).to eq({ key4: "value4", key5: "value5" })
|
414
|
+
expect(config.fixnum1).to eq("")
|
415
|
+
expect(config.fixnum2).to eq("")
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
context "using overwrite_arrays" do
|
421
|
+
context "in configuration phase" do
|
422
|
+
it "should be able to assign a different overwrite_arrays value" do
|
423
|
+
Confset.overwrite_arrays = false
|
424
|
+
|
425
|
+
expect(Confset.overwrite_arrays).to eq(false)
|
426
|
+
end
|
427
|
+
|
428
|
+
it "should have the default overwrite_arrays value equal false" do
|
429
|
+
expect(Confset.overwrite_arrays).to eq(true)
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
context "overwriting" do
|
434
|
+
let(:config) do
|
435
|
+
Confset.overwrite_arrays = true
|
436
|
+
Confset.load_files(["spec/fixtures/overwrite_arrays/config1.yml",
|
437
|
+
"spec/fixtures/overwrite_arrays/config2.yml",
|
438
|
+
"spec/fixtures/overwrite_arrays/config3.yml"])
|
439
|
+
end
|
440
|
+
|
441
|
+
it "should remove elements from settings" do
|
442
|
+
expect(config.array1).to eq(["item4", "item5", "item6"])
|
443
|
+
expect(config.array2.inner).to eq(["item4", "item5", "item6"])
|
444
|
+
expect(config.array3).to eq([])
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
|
449
|
+
context "merging" do
|
450
|
+
let(:config) do
|
451
|
+
Confset.overwrite_arrays = false
|
452
|
+
Confset.load_files(["spec/fixtures/deep_merge/config1.yml",
|
453
|
+
"spec/fixtures/deep_merge/config2.yml"])
|
454
|
+
end
|
455
|
+
|
456
|
+
it "should merge hashes from multiple configs" do
|
457
|
+
expect(config.inner.marshal_dump.keys.size).to eq(6)
|
458
|
+
expect(config.inner2.inner2_inner.marshal_dump.keys.size).to eq(3)
|
459
|
+
end
|
460
|
+
|
461
|
+
it "should merge arrays from multiple configs" do
|
462
|
+
expect(config.arraylist1.size).to eq(6)
|
463
|
+
expect(config.arraylist2.inner.size).to eq(6)
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Confset::Configuration do
|
6
|
+
subject do
|
7
|
+
Module.new do
|
8
|
+
extend Confset::Configuration.new(hello: "world")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "extends a module with additional methods" do
|
13
|
+
expect(subject.hello).to eq("world")
|
14
|
+
expect { subject.hello = "dlrow" }.to change { subject.hello }.to("dlrow")
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
size: 1
|
2
|
+
server: google.com
|
3
|
+
inner:
|
4
|
+
something1: "blah1"
|
5
|
+
something2: "blah2"
|
6
|
+
somethingnil:
|
7
|
+
somethingfalse: false
|
8
|
+
somethingtrue: true
|
9
|
+
|
10
|
+
inner2:
|
11
|
+
inner2_inner:
|
12
|
+
foo1: "blah1"
|
13
|
+
|
14
|
+
|
15
|
+
arraylist1:
|
16
|
+
- 1
|
17
|
+
- 2
|
18
|
+
- 3
|
19
|
+
|
20
|
+
arraylist2:
|
21
|
+
inner:
|
22
|
+
- 1
|
23
|
+
- 2
|
24
|
+
- 3
|
25
|
+
|
26
|
+
hash_array:
|
27
|
+
- 1
|
28
|
+
- inner:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 3
|
@@ -0,0 +1,28 @@
|
|
1
|
+
server: google.com
|
2
|
+
|
3
|
+
inner:
|
4
|
+
something3: "blah3"
|
5
|
+
|
6
|
+
inner2:
|
7
|
+
inner2_inner:
|
8
|
+
foo2: "blah2"
|
9
|
+
foo3: "blah3"
|
10
|
+
|
11
|
+
arraylist1:
|
12
|
+
- 4
|
13
|
+
- 5
|
14
|
+
- 6
|
15
|
+
|
16
|
+
|
17
|
+
arraylist2:
|
18
|
+
inner:
|
19
|
+
- 4
|
20
|
+
- 5
|
21
|
+
- 6
|
22
|
+
|
23
|
+
hash_array:
|
24
|
+
- 2
|
25
|
+
- inner:
|
26
|
+
- 4
|
27
|
+
- 5
|
28
|
+
- 6
|
@@ -0,0 +1 @@
|
|
1
|
+
array: [{a: "one"}]
|
@@ -0,0 +1 @@
|
|
1
|
+
array: [{b: "two"}]
|
File without changes
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
array1:
|
2
|
+
- item1
|
3
|
+
- item2
|
4
|
+
- item3
|
5
|
+
- item4
|
6
|
+
|
7
|
+
array2:
|
8
|
+
inner:
|
9
|
+
- item1
|
10
|
+
- item2
|
11
|
+
- item3
|
12
|
+
- item4
|
13
|
+
|
14
|
+
array3:
|
15
|
+
- item1
|
16
|
+
- item2
|
17
|
+
- item3
|
18
|
+
|
19
|
+
string1: a_string
|
20
|
+
|
21
|
+
string2: another_string
|
22
|
+
|
23
|
+
hash1:
|
24
|
+
key1: value1
|
25
|
+
key2: value2
|
26
|
+
key3: value3
|
27
|
+
|
28
|
+
hash2:
|
29
|
+
key1: value1
|
30
|
+
key2: value2
|
31
|
+
key3: value3
|
32
|
+
|
33
|
+
hash3:
|
34
|
+
key1: value1
|
35
|
+
key2: value2
|
36
|
+
key3: value3
|
37
|
+
|
38
|
+
fixnum1: 1
|
39
|
+
|
40
|
+
fixnum2: 1
|
@@ -0,0 +1,28 @@
|
|
1
|
+
array1:
|
2
|
+
- --item1
|
3
|
+
- --item3
|
4
|
+
- item5
|
5
|
+
|
6
|
+
array2:
|
7
|
+
inner:
|
8
|
+
- --item1
|
9
|
+
- --item3
|
10
|
+
- item5
|
11
|
+
|
12
|
+
array3: --
|
13
|
+
|
14
|
+
string1: --a_string
|
15
|
+
|
16
|
+
string2: --
|
17
|
+
|
18
|
+
hash1:
|
19
|
+
key1: --value1
|
20
|
+
key2: --
|
21
|
+
|
22
|
+
hash2: --
|
23
|
+
|
24
|
+
hash3: --
|
25
|
+
|
26
|
+
fixnum1: --1
|
27
|
+
|
28
|
+
fixnum2: --
|