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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 499c24c1fd7a7e05cd66b372eca6346fb7da29c1
4
- data.tar.gz: ac9627e72c4c9523e9edd4b02dea51a5547a3f3d
3
+ metadata.gz: 5be4c7010520f7045983d8c3c1d3328026a870d9
4
+ data.tar.gz: 82dc97e42a79c6a5ffd3bab665373aad229a28c8
5
5
  SHA512:
6
- metadata.gz: 8756cc7930b50be03ed15cf75b2a296537e9bebeb02457fee2d8a4036289600efdb30527bd60f9a26acb03da2e23106c4d7c3bd9f1891b4c2fb143261a1087b0
7
- data.tar.gz: 4eca2e791b7aae2f972d63826e4d57442cc277e553486411efb41387358def8825827619c9e2ec067bf17b31e782e1dd1a6ba921b8ad04e272eac0dad86fbbee
6
+ metadata.gz: f35abdc5ab055703069215b2cb0a9e798fe9e5d30d5cd6cc57755adfdc2f9e8b60718e07d311aaabc598a644942341ee62e85b75ce130c032407b593e0fe5ecc
7
+ data.tar.gz: f00088e94ee6c7770ec41521ec39b43d6f702743a11a31a251e883b30f3d5915ed89bdef0c70c499f1f65a7e09af818a8d3845ba77a7d7452ef6a36027c4fcf5
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ *.gemfile.lock
4
5
  pkg/*
5
6
  coverage
6
7
  tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --warnings
@@ -0,0 +1,11 @@
1
+ begin
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatters = [
5
+ Coveralls::SimpleCov::Formatter,
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ ]
8
+
9
+ SimpleCov.start
10
+ rescue LoadError
11
+ end
@@ -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
- - rbx-2
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
@@ -1,4 +1,6 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in figgy.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls'
@@ -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
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in figgy.gemspec
4
+ gemspec :path => '..'
5
+
6
+ gem 'rake', '< 11'
7
+ gem 'json', '< 2'
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in figgy.gemspec
4
+ gemspec path: '..'
5
+
6
+ gem 'json', '< 2'
@@ -128,7 +128,7 @@ class Figgy
128
128
  end
129
129
 
130
130
  def overlay_values
131
- @overlays.map &:last
131
+ @overlays.map(&:last)
132
132
  end
133
133
  end
134
134
  end
@@ -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
- result = files.reduce(nil) do |result, file|
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(result))
34
+ deep_freeze(to_figgy_hash(final_result))
35
35
  end
36
36
 
37
37
  # @param [String] name the configuration key to search for
@@ -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"
@@ -1,3 +1,3 @@
1
1
  class Figgy
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -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 |config|
53
- config.define_handler('yml', 'yaml') { |body| YAML.load(body) }
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 |config|
204
- config.root = File.join(current_dir, 'root1')
205
- config.add_root File.join(current_dir, 'root2')
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 |config|
219
- config.root = File.join(current_dir, 'root1')
220
- config.add_root File.join(current_dir, 'root2')
221
- config.define_overlay :environment, 'prod'
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 |config|
234
- config.root = File.join(current_dir, 'root1')
235
- config.add_root File.join(current_dir, 'root2')
236
- config.define_overlay :environment, 'prod'
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 |config|
252
- config.define_overlay :default, nil
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 |config|
260
- config.define_overlay(:environment) { 'prod' }
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 |config|
270
- config.define_overlay :default, nil
271
- config.define_overlay :environment, 'prod'
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 |config|
291
- config.define_overlay :default, 'defaults'
292
- config.define_overlay :environment, 'prod'
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 |config|
302
- config.define_overlay :default, nil
303
- config.define_overlay :environment, 'prod'
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 |config|
325
- config.define_overlay :default, 'defaults'
326
- config.define_overlay :environment, 'prod'
327
- config.define_overlay :local, 'local'
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 |config|
341
- config.define_overlay :default, nil
342
- config.define_overlay :environment, 'prod'
343
- config.define_overlay :country, 'US'
344
- config.define_combined_overlay :environment, :country
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 |config|
355
- config.always_reload = true
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 |config|
366
- config.always_reload = false
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 |config|
382
- config.define_overlay :default, nil
383
- config.define_overlay :environment, 'prod'
384
- config.preload = true
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 |config|
401
- config.define_overlay :default, nil
402
- config.define_overlay :environment, 'prod'
403
- config.define_overlay :local, 'local'
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 |config|
414
- config.preload = true
415
- config.always_reload = true
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 |config|
434
- config.freeze = true
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 |config|
450
- config.freeze = true
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/)
@@ -1,12 +1,4 @@
1
1
  require 'simplecov'
2
- require 'coveralls'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- Coveralls::SimpleCov::Formatter,
6
- SimpleCov::Formatter::HTMLFormatter,
7
- ]
8
-
9
- SimpleCov.start
10
2
 
11
3
  require 'rspec'
12
4
  require 'figgy'
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.2.0
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: 2015-09-11 00:00:00.000000000 Z
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.4.7
129
+ rubygems_version: 2.6.8
140
130
  signing_key:
141
131
  specification_version: 4
142
132
  summary: Configuration file reading