qonfig 0.8.0 → 0.9.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
  SHA256:
3
- metadata.gz: 5c0b292545534b8b00206fd23720da284b5028075c172133d4813e4b6f23f6dc
4
- data.tar.gz: f83fb1c73fa7485ef2fe21c5b27277700255c3a012355576f1261750f130eb06
3
+ metadata.gz: 5ca1aaa94952636ee2ef114d513d68b4836f9162f02b2296ec0fb3fa16037761
4
+ data.tar.gz: afc6d9158a2ce2a3c862987a22c20c922a4025d2025f01d5ca5d591429531c4a
5
5
  SHA512:
6
- metadata.gz: 30bf79cc84a571522d1c7df4c05d3330f5b577fc12597035cdcc5a56b667dbb0e80466781627c0312bebeb31bc72a2f567439cfc11b13ae6519888bbd1bad611
7
- data.tar.gz: 80c56739bcfd8664485fae8c5a080041a4357bbc72f90cf6f6b4137c0c4076b0159458d8f4397bab4892173e12dc1c12db01b01d922b4a66f6fb723f44280297
6
+ metadata.gz: 895e6bfe6c185e71d81f9a8f55740f48e12b2aff55cd3116ae12f9b68423b7726317263f33ab49e85cc670608a159de2efcc91882ec79dd00b40236f2f41d91f
7
+ data.tar.gz: 82187c64659aad286d3370e7da6ae8e7506a988a4ff056181df8073aa0039b4bc9210fdaa70cd4a11f27b0fc3c2be26651f96ce42e5fa5c50b1d68739436c42c
data/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.9.0] - 2018-11-28
5
+ ### Added
6
+ - `#slice` - get a slice of config options as a hash set (works in a `#dig` manner);
7
+
4
8
  ## [0.8.0] - 2018-11-21
5
9
  ### Changed
6
10
  - `expose_yaml`, `load_from_yaml`, `load_from_json` and `load_from_self` treats empty hash (`{}`)
7
- as an option with empty hash value (previously treated as a nested setting);
11
+ as an option with empty hash value (previously treated as a nested setting without options);
8
12
 
9
13
  ## [0.7.0] - 2018-10-20
10
14
  ### Added
data/README.md CHANGED
@@ -21,7 +21,7 @@ require 'qonfig'
21
21
 
22
22
  ## Usage
23
23
 
24
- - [Definition and Access](#definition-and-access)
24
+ - [Definition and Settings Access](#definition-and-access)
25
25
  - [Configuration](#configuration)
26
26
  - [Inheritance](#inheritance)
27
27
  - [Composition](#composition)
@@ -43,6 +43,7 @@ require 'qonfig'
43
43
  ### Definition and Access
44
44
 
45
45
  ```ruby
46
+ # --- definition ---
46
47
  class Config < Qonfig::DataSet
47
48
  # nil by default
48
49
  setting :project_id
@@ -60,7 +61,9 @@ class Config < Qonfig::DataSet
60
61
  end
61
62
  end
62
63
 
63
- config = Config.new
64
+ config = Config.new # your configuration object instance
65
+
66
+ # --- setting access ---
64
67
 
65
68
  # get option value via method
66
69
  config.settings.project_id # => nil
@@ -89,6 +92,12 @@ config[:enable_graphql] # => false
89
92
  # get option value in Hash#dig manner (and fail when the required key does not exist)
90
93
  config.dig(:vendor_api, :host) # => 'app.service.com' # (key exists)
91
94
  config.dig(:vendor_api, :port) # => Qonfig::UnknownSettingError # (key does not exist)
95
+
96
+ # get a hash slice of setting options (and fail when the required key does not exist)
97
+ config.slice(:vendor_api) # => { 'vendor_api' => { 'host' => 'app_service', 'user' => 'test_user' } }
98
+ config.slice(:vendor_api, :user) # => { 'user' => 'test_user' }
99
+ config.slice(:project_api) # => Qonfig::UnknownSettingError # (key does not exist)
100
+ config.slice(:vendor_api, :port) # => Qonfig::UnknownSettingError # (key does not exist)
92
101
  ```
93
102
 
94
103
  ---
@@ -95,6 +95,15 @@ module Qonfig
95
95
  thread_safe_access { settings.__dig__(*keys) }
96
96
  end
97
97
 
98
+ # @param keys [Array<String, Symbol>]
99
+ # @return [Hash]
100
+ #
101
+ # @api public
102
+ # @since 0.9.0
103
+ def slice(*keys)
104
+ thread_safe_access { settings.__slice__(*keys) }
105
+ end
106
+
98
107
  # @return [void]
99
108
  #
100
109
  # @api public
@@ -94,6 +94,15 @@ module Qonfig
94
94
  __lock__.thread_safe_access { __deep_access__(*keys) }
95
95
  end
96
96
 
97
+ # @param keys [Array<String, Symbol>]
98
+ # @return [Hash]
99
+ #
100
+ # @api private
101
+ # @since 0.9.0
102
+ def __slice__(*keys)
103
+ __lock__.thread_safe_access { __deep_slice__(*keys) }
104
+ end
105
+
97
106
  # @return [Hash]
98
107
  #
99
108
  # @api private
@@ -266,7 +275,6 @@ module Qonfig
266
275
  end
267
276
 
268
277
  # @param keys [Array<Symbol, String>]
269
- # @option result [Object]
270
278
  # @return [Object]
271
279
  #
272
280
  # @raise [Qonfig::ArgumentError]
@@ -293,6 +301,23 @@ module Qonfig
293
301
  end
294
302
  end
295
303
 
304
+ # @param keys [Array<Symbol, String>]
305
+ # @return [Hash]
306
+ #
307
+ # @raise [Qonfig::ArgumentError]
308
+ # @raise [Qonfig::UnknownSettingError]
309
+ #
310
+ # @api private
311
+ # @since 0.9.0
312
+ def __deep_slice__(*keys)
313
+ {}.tap do |result|
314
+ __deep_access__(*keys).tap do |setting|
315
+ required_key = __indifferently_accessable_option_key__(keys.last)
316
+ result[required_key] = setting.is_a?(Qonfig::Settings) ? setting.__to_h__ : setting
317
+ end
318
+ end
319
+ end
320
+
296
321
  # @param options_part [Hash]
297
322
  # @return [Hash]
298
323
  #
@@ -5,5 +5,5 @@ module Qonfig
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.8.0'
8
+ VERSION = '0.9.0'
9
9
  end
data/qonfig.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- # codning: utf-8
1
+ # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
4
  lib = File.expand_path('lib', __dir__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qonfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls