figgy 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.simplecov +11 -0
- data/.travis.yml +10 -3
- data/Gemfile +3 -1
- data/figgy.gemspec +0 -2
- data/gemfiles/ruby-1.8.7.gemfile +7 -0
- data/gemfiles/ruby-1.9.gemfile +6 -0
- data/lib/figgy/configuration.rb +1 -1
- data/lib/figgy/finder.rb +2 -2
- data/lib/figgy/hash.rb +8 -0
- data/lib/figgy/version.rb +1 -1
- data/spec/figgy_spec.rb +75 -54
- data/spec/spec_helper.rb +0 -8
- metadata +7 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5be4c7010520f7045983d8c3c1d3328026a870d9
|
4
|
+
data.tar.gz: 82dc97e42a79c6a5ffd3bab665373aad229a28c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f35abdc5ab055703069215b2cb0a9e798fe9e5d30d5cd6cc57755adfdc2f9e8b60718e07d311aaabc598a644942341ee62e85b75ce130c032407b593e0fe5ecc
|
7
|
+
data.tar.gz: f00088e94ee6c7770ec41521ec39b43d6f702743a11a31a251e883b30f3d5915ed89bdef0c70c499f1f65a7e09af818a8d3845ba77a7d7452ef6a36027c4fcf5
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.simplecov
ADDED
data/.travis.yml
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 1.8.7
|
5
|
-
- 1.9
|
6
4
|
- 2.0
|
7
5
|
- 2.1
|
8
6
|
- 2.2
|
9
|
-
-
|
7
|
+
- 2.3
|
8
|
+
|
9
|
+
before_install: gem install bundler
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
include:
|
13
|
+
- rvm: 1.8.7
|
14
|
+
gemfile: gemfiles/ruby-1.8.7.gemfile
|
15
|
+
- rvm: 1.9
|
16
|
+
gemfile: gemfiles/ruby-1.9.gemfile
|
data/Gemfile
CHANGED
data/figgy.gemspec
CHANGED
@@ -21,7 +21,5 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency "rake"
|
22
22
|
s.add_development_dependency "rspec", '~> 3.0'
|
23
23
|
s.add_development_dependency "simplecov", '~> 0.9'
|
24
|
-
s.add_development_dependency "coveralls"
|
25
|
-
s.add_development_dependency "rest-client", '1.6.8' if RUBY_VERSION == "1.8.7"
|
26
24
|
s.add_development_dependency "heredoc_unindent"
|
27
25
|
end
|
data/lib/figgy/configuration.rb
CHANGED
data/lib/figgy/finder.rb
CHANGED
@@ -22,7 +22,7 @@ class Figgy
|
|
22
22
|
raise(Figgy::FileNotFound, "Can't find config files for key: #{name.inspect}")
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
final_result = files.reduce(nil) do |result, file|
|
26
26
|
object = @config.handler_for(file).call(File.read(file))
|
27
27
|
if result && result.respond_to?(:merge)
|
28
28
|
deep_merge(result, object)
|
@@ -31,7 +31,7 @@ class Figgy
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
deep_freeze(to_figgy_hash(
|
34
|
+
deep_freeze(to_figgy_hash(final_result))
|
35
35
|
end
|
36
36
|
|
37
37
|
# @param [String] name the configuration key to search for
|
data/lib/figgy/hash.rb
CHANGED
@@ -17,6 +17,10 @@ class Figgy
|
|
17
17
|
super(convert_key(key), value)
|
18
18
|
end
|
19
19
|
|
20
|
+
def fetch(key, *extras)
|
21
|
+
super(convert_key(key), *extras)
|
22
|
+
end
|
23
|
+
|
20
24
|
def delete(key)
|
21
25
|
super(convert_key(key))
|
22
26
|
end
|
@@ -36,6 +40,10 @@ class Figgy
|
|
36
40
|
self
|
37
41
|
end
|
38
42
|
|
43
|
+
def dig(*keys)
|
44
|
+
super(*keys.map { |k| convert_key(k) })
|
45
|
+
end if ::Hash.method_defined?(:dig)
|
46
|
+
|
39
47
|
def respond_to?(m, *)
|
40
48
|
super || key?(convert_key(m))
|
41
49
|
end if RUBY_VERSION == "1.8.7"
|
data/lib/figgy/version.rb
CHANGED
data/spec/figgy_spec.rb
CHANGED
@@ -49,8 +49,8 @@ describe Figgy do
|
|
49
49
|
write_config 'values.yml', 'foo: 1'
|
50
50
|
write_config 'values.yaml', 'foo: 2'
|
51
51
|
|
52
|
-
config = test_config do |
|
53
|
-
|
52
|
+
config = test_config do |cfg|
|
53
|
+
cfg.define_handler('yml', 'yaml') { |body| YAML.load(body) }
|
54
54
|
end
|
55
55
|
expect(config.values.foo).to eq(2)
|
56
56
|
end
|
@@ -170,6 +170,27 @@ describe Figgy do
|
|
170
170
|
it "can merge with another hash" do
|
171
171
|
expect(config.values.with.merge(config.values.another)).to eq(config.values.altogether)
|
172
172
|
end
|
173
|
+
|
174
|
+
it 'can fetch a key with a default value' do
|
175
|
+
expect(config.values.without.fetch('two')).to eq(config.values.without.two)
|
176
|
+
expect(config.values.without.fetch(:two)).to eq(config.values.without.two)
|
177
|
+
|
178
|
+
expect { config.values.without.fetch('one') }.to raise_error(/key not found/)
|
179
|
+
expect { config.values.without.fetch(:one) }.to raise_error(/key not found/)
|
180
|
+
|
181
|
+
expect(config.values.without.fetch('one', 1)).to eq 1
|
182
|
+
expect(config.values.without.fetch(:one, 1)).to eq 1
|
183
|
+
|
184
|
+
expect(config.values.without.fetch('three') { 3 } ).to eq 3
|
185
|
+
expect(config.values.without.fetch(:three) { 3 } ).to eq 3
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'can dig for nested values' do
|
189
|
+
skip if RUBY_VERSION < '2.3.0'
|
190
|
+
|
191
|
+
expect(config.values.dig(:without, 'two')).to eq config.values.without.two
|
192
|
+
expect(config.values.dig(:without, 'one')).to eq nil
|
193
|
+
end
|
173
194
|
end
|
174
195
|
end
|
175
196
|
|
@@ -200,9 +221,9 @@ describe Figgy do
|
|
200
221
|
write_config 'root1/values', 'foo: 1'
|
201
222
|
write_config 'root2/values', 'bar: 2'
|
202
223
|
|
203
|
-
config = test_config do |
|
204
|
-
|
205
|
-
|
224
|
+
config = test_config do |cfg|
|
225
|
+
cfg.root = File.join(current_dir, 'root1')
|
226
|
+
cfg.add_root File.join(current_dir, 'root2')
|
206
227
|
end
|
207
228
|
|
208
229
|
expect(config.values.foo).to eq(1)
|
@@ -215,10 +236,10 @@ describe Figgy do
|
|
215
236
|
write_config 'root2/values', 'bar: 1'
|
216
237
|
write_config 'root2/prod/values', 'bar: 2'
|
217
238
|
|
218
|
-
config = test_config do |
|
219
|
-
|
220
|
-
|
221
|
-
|
239
|
+
config = test_config do |cfg|
|
240
|
+
cfg.root = File.join(current_dir, 'root1')
|
241
|
+
cfg.add_root File.join(current_dir, 'root2')
|
242
|
+
cfg.define_overlay :environment, 'prod'
|
222
243
|
end
|
223
244
|
|
224
245
|
expect(config.values.foo).to eq(2)
|
@@ -230,10 +251,10 @@ describe Figgy do
|
|
230
251
|
write_config 'root1/prod/values', 'foo: 2'
|
231
252
|
write_config 'root2/prod/values', 'foo: 3'
|
232
253
|
|
233
|
-
config = test_config do |
|
234
|
-
|
235
|
-
|
236
|
-
|
254
|
+
config = test_config do |cfg|
|
255
|
+
cfg.root = File.join(current_dir, 'root1')
|
256
|
+
cfg.add_root File.join(current_dir, 'root2')
|
257
|
+
cfg.define_overlay :environment, 'prod'
|
237
258
|
end
|
238
259
|
|
239
260
|
expect(config.values.foo).to eq(2)
|
@@ -248,16 +269,16 @@ describe Figgy do
|
|
248
269
|
|
249
270
|
it "interprets a nil overlay value as an indication to read from the config root" do
|
250
271
|
write_config 'values', "foo: 1"
|
251
|
-
config = test_config do |
|
252
|
-
|
272
|
+
config = test_config do |cfg|
|
273
|
+
cfg.define_overlay :default, nil
|
253
274
|
end
|
254
275
|
expect(config.values).to eq({ "foo" => 1 })
|
255
276
|
end
|
256
277
|
|
257
278
|
it "allows the overlay's value to be the result of a block" do
|
258
279
|
write_config 'prod/values', "foo: 1"
|
259
|
-
config = test_config do |
|
260
|
-
|
280
|
+
config = test_config do |cfg|
|
281
|
+
cfg.define_overlay(:environment) { 'prod' }
|
261
282
|
end
|
262
283
|
expect(config.values).to eq({ "foo" => 1 })
|
263
284
|
end
|
@@ -266,9 +287,9 @@ describe Figgy do
|
|
266
287
|
write_config 'some_string', "foo bar baz"
|
267
288
|
write_config 'prod/some_string', "foo bar baz quux"
|
268
289
|
|
269
|
-
config = test_config do |
|
270
|
-
|
271
|
-
|
290
|
+
config = test_config do |cfg|
|
291
|
+
cfg.define_overlay :default, nil
|
292
|
+
cfg.define_overlay :environment, 'prod'
|
272
293
|
end
|
273
294
|
|
274
295
|
expect(config.some_string).to eq("foo bar baz quux")
|
@@ -287,9 +308,9 @@ describe Figgy do
|
|
287
308
|
quux: hi!
|
288
309
|
YML
|
289
310
|
|
290
|
-
config = test_config do |
|
291
|
-
|
292
|
-
|
311
|
+
config = test_config do |cfg|
|
312
|
+
cfg.define_overlay :default, 'defaults'
|
313
|
+
cfg.define_overlay :environment, 'prod'
|
293
314
|
end
|
294
315
|
|
295
316
|
expect(config.values).to eq({ "foo" => { "bar" => 1, "baz" => 3 }, "quux" => "hi!" })
|
@@ -298,9 +319,9 @@ describe Figgy do
|
|
298
319
|
it "can use both a nil overlay and an overlay with a value" do
|
299
320
|
write_config 'values', "foo: 1\nbar: 2"
|
300
321
|
write_config 'prod/values', "foo: 2"
|
301
|
-
config = test_config do |
|
302
|
-
|
303
|
-
|
322
|
+
config = test_config do |cfg|
|
323
|
+
cfg.define_overlay :default, nil
|
324
|
+
cfg.define_overlay :environment, 'prod'
|
304
325
|
end
|
305
326
|
expect(config.values).to eq({ "foo" => 2, "bar" => 2 })
|
306
327
|
end
|
@@ -321,10 +342,10 @@ describe Figgy do
|
|
321
342
|
baz: 3
|
322
343
|
YML
|
323
344
|
|
324
|
-
config = test_config do |
|
325
|
-
|
326
|
-
|
327
|
-
|
345
|
+
config = test_config do |cfg|
|
346
|
+
cfg.define_overlay :default, 'defaults'
|
347
|
+
cfg.define_overlay :environment, 'prod'
|
348
|
+
cfg.define_overlay :local, 'local'
|
328
349
|
end
|
329
350
|
|
330
351
|
expect(config.values).to eq({ "foo" => 1, "bar" => 2, "baz" => 3 })
|
@@ -337,11 +358,11 @@ describe Figgy do
|
|
337
358
|
write_config 'prod/keys', "foo: 2"
|
338
359
|
write_config 'prod_US/keys', "foo: 3"
|
339
360
|
|
340
|
-
config = test_config do |
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
361
|
+
config = test_config do |cfg|
|
362
|
+
cfg.define_overlay :default, nil
|
363
|
+
cfg.define_overlay :environment, 'prod'
|
364
|
+
cfg.define_overlay :country, 'US'
|
365
|
+
cfg.define_combined_overlay :environment, :country
|
345
366
|
end
|
346
367
|
|
347
368
|
expect(config.keys).to eq({ "foo" => 3 })
|
@@ -351,8 +372,8 @@ describe Figgy do
|
|
351
372
|
context "reloading" do
|
352
373
|
it "can reload on each access when config.always_reload = true" do
|
353
374
|
write_config 'values', 'foo: 1'
|
354
|
-
config = test_config do |
|
355
|
-
|
375
|
+
config = test_config do |cfg|
|
376
|
+
cfg.always_reload = true
|
356
377
|
end
|
357
378
|
expect(config.values).to eq({ "foo" => 1 })
|
358
379
|
|
@@ -362,8 +383,8 @@ describe Figgy do
|
|
362
383
|
|
363
384
|
it "does not reload when config.always_reload = false" do
|
364
385
|
write_config 'values', 'foo: 1'
|
365
|
-
config = test_config do |
|
366
|
-
|
386
|
+
config = test_config do |cfg|
|
387
|
+
cfg.always_reload = false
|
367
388
|
end
|
368
389
|
expect(config.values).to eq({ "foo" => 1 })
|
369
390
|
|
@@ -378,10 +399,10 @@ describe Figgy do
|
|
378
399
|
write_config 'prod/values', 'foo: 2'
|
379
400
|
write_config 'prod/prod_only', 'bar: baz'
|
380
401
|
|
381
|
-
config = test_config do |
|
382
|
-
|
383
|
-
|
384
|
-
|
402
|
+
config = test_config do |cfg|
|
403
|
+
cfg.define_overlay :default, nil
|
404
|
+
cfg.define_overlay :environment, 'prod'
|
405
|
+
cfg.preload = true
|
385
406
|
end
|
386
407
|
|
387
408
|
write_config 'prod/values', 'foo: 3'
|
@@ -397,10 +418,10 @@ describe Figgy do
|
|
397
418
|
write_config 'prod/lonely.yml', 'only: yml'
|
398
419
|
write_config 'local/json_values.json', '{ "json": true }'
|
399
420
|
|
400
|
-
config = test_config do |
|
401
|
-
|
402
|
-
|
403
|
-
|
421
|
+
config = test_config do |cfg|
|
422
|
+
cfg.define_overlay :default, nil
|
423
|
+
cfg.define_overlay :environment, 'prod'
|
424
|
+
cfg.define_overlay :local, 'local'
|
404
425
|
end
|
405
426
|
|
406
427
|
finder = config.instance_variable_get(:@finder)
|
@@ -410,9 +431,9 @@ describe Figgy do
|
|
410
431
|
it "still supports reloading when preloading is enabled" do
|
411
432
|
write_config 'values', 'foo: 1'
|
412
433
|
|
413
|
-
config = test_config do |
|
414
|
-
|
415
|
-
|
434
|
+
config = test_config do |cfg|
|
435
|
+
cfg.preload = true
|
436
|
+
cfg.always_reload = true
|
416
437
|
end
|
417
438
|
|
418
439
|
expect(config.values['foo']).to eq(1)
|
@@ -430,8 +451,8 @@ describe Figgy do
|
|
430
451
|
|
431
452
|
it "freezes the results when config.freeze = true" do
|
432
453
|
write_config 'values', "foo: '1'"
|
433
|
-
config = test_config do |
|
434
|
-
|
454
|
+
config = test_config do |cfg|
|
455
|
+
cfg.freeze = true
|
435
456
|
end
|
436
457
|
expect(config.values).to be_frozen
|
437
458
|
end
|
@@ -446,8 +467,8 @@ describe Figgy do
|
|
446
467
|
- and: an inner hash
|
447
468
|
YML
|
448
469
|
|
449
|
-
config = test_config do |
|
450
|
-
|
470
|
+
config = test_config do |cfg|
|
471
|
+
cfg.freeze = true
|
451
472
|
end
|
452
473
|
|
453
474
|
expect { config.values.outer.array[2]['and'] = 'foo' }.to raise_error(/can't modify frozen/)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: figgy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Hargraves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: coveralls
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: heredoc_unindent
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,12 +88,16 @@ extensions: []
|
|
102
88
|
extra_rdoc_files: []
|
103
89
|
files:
|
104
90
|
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".simplecov"
|
105
93
|
- ".travis.yml"
|
106
94
|
- Gemfile
|
107
95
|
- LICENSE.txt
|
108
96
|
- README.md
|
109
97
|
- Rakefile
|
110
98
|
- figgy.gemspec
|
99
|
+
- gemfiles/ruby-1.8.7.gemfile
|
100
|
+
- gemfiles/ruby-1.9.gemfile
|
111
101
|
- lib/figgy.rb
|
112
102
|
- lib/figgy/configuration.rb
|
113
103
|
- lib/figgy/finder.rb
|
@@ -136,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
126
|
version: '0'
|
137
127
|
requirements: []
|
138
128
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.6.8
|
140
130
|
signing_key:
|
141
131
|
specification_version: 4
|
142
132
|
summary: Configuration file reading
|