qonfig 0.18.0 → 0.18.1

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
  SHA256:
3
- metadata.gz: ec197a7e1d7185ff8c4e5906e244c5cbce610d1449dc60cfb1d2a167a2e79921
4
- data.tar.gz: 47d2d394cfcc97cf5ab58a198865490ecd4c9494c7ee7096474ff7a6f0c5d7f2
3
+ metadata.gz: 6ed2259a3f11b04bb0730f73f982228c20263340cd2aa0bd5c4e8d2a418ba04c
4
+ data.tar.gz: 318f345a9f6dc250725ad74bc34a12d087e9bf50d8c7c54f3cbc5d29cb211749
5
5
  SHA512:
6
- metadata.gz: 87e2688f74aa2dba959c423ea79ec36686c1873e20654826ad4eefc599da6f0d9967066e8de605b0f0a83d58465ecdb3f061e193fedc1aef6223d03794ffff7f
7
- data.tar.gz: 107ccfc0dfe0ee109765699c4af58d431edd572d6ea30dace2449ff87d991bc8dbb555dedf95ccf7d3101cac2fb728fd7e44dec5c8a04a74583b006926e8ec46
6
+ metadata.gz: 3c97a92c975202ff93d5317b3e82552a54af184f47980d146239edb528fb7d4523927939d43b0c7d98ae8a1a85b3f29cc0368eaebc164e3b930eebb477c7e10f
7
+ data.tar.gz: ea7e2b6e6def6d70eb7fa67f3e83c1e7920068ae253b3e2042a44164bf9486120e37395beee81c318c9ce450106ce5f4f4a0180c53f53c9e1dd3b116a4582508
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.18.1] - 2019-11-05
5
+ ### Added
6
+ - New `yield_all:` attribute for `#deep_each_setting` method (`#deep_each_setting(yield_all: false, &block)`))
7
+ - `yield_all:` means "yield all config objects" (end values and root setting objects those have nested settings) (`false` by default)
8
+
9
+ ### Fixed
10
+ - `#keys(all_variants: true)` returns incorrect set of keys when some of keys has name in dot-notated format;
11
+
4
12
  ## [0.18.0] - 2019-11-04
5
13
  ### Added
6
14
  - `#keys` - returns a list of all config keys in dot-notation format;
data/README.md CHANGED
@@ -552,10 +552,10 @@ config.settings.web_api # => "api.google.com"
552
552
 
553
553
  - `#each_setting { |key, value| }`
554
554
  - iterates over the root setting keys;
555
- - `#deep_each_setting { |key, value| }`
555
+ - `#deep_each_setting(yield_all: false) { |key, value| }`
556
556
  - iterates over all setting keys (deep inside);
557
557
  - key object is represented as a string of `.`-joined setting key names;
558
-
558
+ - `yield_all:` means "yield all config objects" (end values and root setting objects those have nested settings) (`false` by default);
559
559
 
560
560
  ```ruby
561
561
  class Config < Qonfig::DataSet
@@ -598,6 +598,21 @@ config.deep_each_setting { |key, value| { key => value } }
598
598
  { 'telegraf_prefix' => 'test' }
599
599
  ```
600
600
 
601
+ #### .deep_each_setting(yield_all: true)
602
+
603
+ ```ruby
604
+ config.deep_each_setting(yield_all: true) { |key, value| { key => value } }
605
+
606
+ # result of each step:
607
+ { 'db' => <Qonfig::Settings:0x00007ff8> } # (yield_all: true)
608
+ { 'db.creds' => <Qonfig::Settings:0x00002ff1> } # (yield_all: true)
609
+ { 'db.creds.user' => 'D@iVeR' }
610
+ { 'db.creds.password' => 'test123' }
611
+ { 'db.crds.data' => { test: false } }
612
+ { 'telegraf_url' => 'udp://localhost:8094' }
613
+ { 'telegraf_prefix' => 'test' }
614
+ ```
615
+
601
616
  ---
602
617
 
603
618
  ### List of config keys
@@ -281,6 +281,7 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
281
281
  end
282
282
 
283
283
  # @param block [Proc]
284
+ # @option yield_all [Boolean]
284
285
  # @return [Enumerable]
285
286
  #
286
287
  # @yield [setting_key, setting_value]
@@ -289,8 +290,8 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
289
290
  #
290
291
  # @api public
291
292
  # @since 0.13.0
292
- def deep_each_setting(&block)
293
- thread_safe_access { settings.__deep_each_setting__(&block) }
293
+ def deep_each_setting(yield_all: false, &block)
294
+ thread_safe_access { settings.__deep_each_setting__(yield_all: yield_all, &block) }
294
295
  end
295
296
 
296
297
  # @return [Boolean]
@@ -59,6 +59,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
59
59
 
60
60
  # @param initial_setting_key [String, NilClass]
61
61
  # @param block [Proc]
62
+ # @option yield_all [Boolean]
62
63
  # @return [Enumerable]
63
64
  #
64
65
  # @yield [key, value]
@@ -67,9 +68,9 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
67
68
  #
68
69
  # @api private
69
70
  # @since 0.13.0
70
- def __deep_each_setting__(initial_setting_key = nil, &block)
71
+ def __deep_each_setting__(initial_setting_key = nil, yield_all: false, &block)
71
72
  __lock__.thread_safe_access do
72
- __deep_each_key_value_pair__(initial_setting_key, &block)
73
+ __deep_each_key_value_pair__(initial_setting_key, yield_all: yield_all, &block)
73
74
  end
74
75
  end
75
76
 
@@ -312,35 +313,19 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
312
313
  # @api private
313
314
  # @since 0.18.0
314
315
  def __setting_keys__(all_variants: false)
315
- # NOTE: generate a set of keys return simple 'a.b.c.d'
316
- setting_keys_set = Set.new.tap do |setting_keys|
317
- __deep_each_key_value_pair__ do |setting_key, _setting_value|
316
+ # NOTE: (if all_variants == true)
317
+ # We have { a: { b: { c: { d : 1 } } } }
318
+ # Its mean that we have these keys:
319
+ # - 'a' # => returns { b: { c: { d: 1 } } }
320
+ # - 'a.b' # => returns { c: { d: 1 } }
321
+ # - 'a.b.c' # => returns { d: 1 }
322
+ # - 'a.b.c.d' # => returns 1
323
+
324
+ Set.new.tap do |setting_keys|
325
+ __deep_each_key_value_pair__(yield_all: all_variants) do |setting_key, _setting_value|
318
326
  setting_keys << setting_key
319
327
  end
320
- end
321
-
322
- if all_variants
323
- # NOTE:
324
- # We have { a: { b: { c: { d : 1 } } } }
325
- # Its mean that we have these keys:
326
- # - 'a' # => returns { b: { c: { d: 1 } } }
327
- # - 'a.b' # => returns { c: { d: 1 } }
328
- # - 'a.b.c' # => returns { d: 1 }
329
- # - 'a.b.c.d' # => returns 1
330
- # So, get them all :)
331
-
332
- setting_keys_set.each_with_object(Set.new) do |setting_key, varianted_setting_keys|
333
- setting_key_paths = setting_key.split('.')
334
- combination_size = setting_key_paths.size
335
-
336
- combination_size.times do |merged_key_patterns_count|
337
- sub_setting_key = setting_key_paths.slice(0..merged_key_patterns_count).join('.')
338
- varianted_setting_keys << sub_setting_key
339
- end
340
- end
341
- else
342
- setting_keys_set
343
- end
328
+ end.to_a
344
329
  end
345
330
 
346
331
  # @return [Array<String>]
@@ -378,6 +363,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
378
363
 
379
364
  # @param initial_setting_key [String, NilClass]
380
365
  # @param block [Proc]
366
+ # @option yield_all [Boolean]
381
367
  # @return [Enumerator]
382
368
  #
383
369
  # @yield [setting_key, setting_value]
@@ -386,14 +372,15 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
386
372
  #
387
373
  # @api private
388
374
  # @since 0.13.0
389
- def __deep_each_key_value_pair__(initial_setting_key = nil, &block)
375
+ def __deep_each_key_value_pair__(initial_setting_key = nil, yield_all: false, &block)
390
376
  enumerator = Enumerator.new do |yielder|
391
377
  __each_key_value_pair__ do |setting_key, setting_value|
392
378
  final_setting_key =
393
379
  initial_setting_key ? "#{initial_setting_key}.#{setting_key}" : setting_key
394
380
 
395
381
  if __is_a_setting__(setting_value)
396
- setting_value.__deep_each_setting__(final_setting_key, &block)
382
+ yielder.yield(final_setting_key, setting_value) if yield_all
383
+ setting_value.__deep_each_setting__(final_setting_key, yield_all: yield_all, &block)
397
384
  else
398
385
  yielder.yield(final_setting_key, setting_value)
399
386
  end
@@ -5,5 +5,5 @@ module Qonfig
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.18.0'
8
+ VERSION = '0.18.1'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qonfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov