qonfig 0.15.0 → 0.16.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: 985a8b16d7fd6a86ec41fea68569c83f283e60f293ac8bca047ad4b0ca21b563
4
- data.tar.gz: b94a684b24f696a67ce8c6a5ff2ceec98da628a9768ce6689fe1bd4a49ef130c
3
+ metadata.gz: d31eafd74da18cba4ef82848b5046df61c5804a1913b5355b76a31a35baaede0
4
+ data.tar.gz: 6b8d69f450b342d5a825de242fff11c016aadbcd0063c801e7d07e7c28508110
5
5
  SHA512:
6
- metadata.gz: cc879948b2e2a88aa1e207802d6cc7870944af239d67a0ab8e0c1dea21e8410eb0dd4d7063830f8ee0fd37cf7f0a2b61606d9fec6504918e1243128adacb70a3
7
- data.tar.gz: ce80093052178e5d59c5b8f713029da8e74cc1ac14febcfc3fefd7023e0b37b2b1422638ac0ba4dc14e7b90b45a4094bde876274c757b8eea6df2194285c52cd
6
+ metadata.gz: '08ad599216433bc7e81a679d02d2cfd81162ca1895698f3086a174e559744c816cc3a171be925846ad3e84cee5234eb4e9701acc8be13323d1e24eab3572f893'
7
+ data.tar.gz: 3d83aaa571007f9502810f58d1eecdcaa92a0a5a202708ef35191f39f5c283f923a3c87ba91d5aaf4b42e3c45a9ade01a70eb53a843d53ed88f0ab4ef317e775
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ inherit_gem:
4
4
  - lib/rubocop.rspec.yml
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 2.6.3
7
+ TargetRubyVersion: 2.6.4
8
8
  Include:
9
9
  - lib/**/*.rb
10
10
  - spec/**/*.rb
data/.travis.yml CHANGED
@@ -5,13 +5,13 @@ matrix:
5
5
  - rvm: 2.3.8
6
6
  gemfile: gemfiles/with_external_deps.gemfile
7
7
  env: TEST_PLUGINS=true
8
- - rvm: 2.4.6
8
+ - rvm: 2.4.7
9
9
  gemfile: gemfiles/with_external_deps.gemfile
10
10
  env: TEST_PLUGINS=true
11
- - rvm: 2.5.5
11
+ - rvm: 2.5.6
12
12
  gemfile: gemfiles/with_external_deps.gemfile
13
13
  env: TEST_PLUGINS=true
14
- - rvm: 2.6.3
14
+ - rvm: 2.6.4
15
15
  gemfile: gemfiles/with_external_deps.gemfile
16
16
  env: TEST_PLUGINS=true
17
17
  - rvm: ruby-head
@@ -22,11 +22,11 @@ matrix:
22
22
  env: TEST_PLUGINS=true
23
23
  - rvm: 2.3.8
24
24
  gemfile: gemfiles/without_external_deps.gemfile
25
- - rvm: 2.4.6
25
+ - rvm: 2.4.7
26
26
  gemfile: gemfiles/without_external_deps.gemfile
27
- - rvm: 2.5.5
27
+ - rvm: 2.5.6
28
28
  gemfile: gemfiles/without_external_deps.gemfile
29
- - rvm: 2.6.3
29
+ - rvm: 2.6.4
30
30
  gemfile: gemfiles/without_external_deps.gemfile
31
31
  - rvm: ruby-head
32
32
  gemfile: gemfiles/without_external_deps.gemfile
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.16.0] - 2019-09-13
5
+ ### Added
6
+ - `Qonfig::DataSet.build(&config_klass_definitions)` - build config instance immidietly without `Qonfig::DataSet`-class definition;
7
+ - `#subset` - get a subset of config settings represented as a hash;
8
+
4
9
  ## [0.15.0] - 2019-09-02
5
10
  ### Added
6
- - `:format`-option for `load_from_self` and `expose_self` commands thath identifies which data format
11
+ - `:format`-option for `load_from_self` and `expose_self` commands that identifies which data format
7
12
  should be chosen for parsing;
8
13
 
9
14
  ## [0.14.0] - 2019-08-28
data/README.md CHANGED
@@ -24,11 +24,18 @@ require 'qonfig'
24
24
 
25
25
  - [Definition](#definition)
26
26
  - [Definition and Settings Access](#definition-and-access)
27
+ - [access via method](#access-via-method)
28
+ - [index-method](#index-method)
29
+ - [.dig](#dig)
30
+ - [.slice](#slice)
31
+ - [.slice_value](#slice_value)
32
+ - [.subset](#subset)
27
33
  - [Configuration](#configuration)
28
34
  - [Inheritance](#inheritance)
29
35
  - [Composition](#composition)
30
36
  - [Hash representation](#hash-representation)
31
37
  - [Smart Mixin](#smart-mixin) (`Qonfig::Configurable`)
38
+ - [Instantiation without class definition](#instantiation-without-class-definition) (`Qonfig::DataSet.build(&definitions)`)
32
39
  - [Interaction](#interaction)
33
40
  - [Iteration over setting keys](#iteration-over-setting-keys) (`#each_setting`, `#deep_each_setting`)
34
41
  - [Config reloading](#config-reloading) (reload config definitions and option values)
@@ -86,18 +93,32 @@ class Config < Qonfig::DataSet
86
93
  setting :vendor_api do
87
94
  setting :user, 'test_user'
88
95
  end
96
+
97
+ # deep nesting
98
+ setting :credentials do
99
+ setting :user do
100
+ setting :login, 'D@iVeR'
101
+ setting :password, 'test123'
102
+ end
103
+ end
89
104
  end
90
105
 
91
106
  config = Config.new # your configuration object instance
107
+ ```
92
108
 
93
- # --- setting access ---
109
+ #### access via method
94
110
 
111
+ ```ruby
95
112
  # get option value via method
96
113
  config.settings.project_id # => nil
97
114
  config.settings.vendor_api.host # => 'app.service.com'
98
115
  config.settings.vendor_api.user # => 'test_user'
99
116
  config.settings.enable_graphql # => false
117
+ ```
100
118
 
119
+ #### index-method []
120
+
121
+ ```ruby
101
122
  # get option value via index (with indifferent (string / symbol / mixed) access)
102
123
  config.settings[:project_id] # => nil
103
124
  config.settings[:vendor_api][:host] # => 'app.service.com'
@@ -115,24 +136,51 @@ config['project_id'] # => nil
115
136
  config['enable_graphql'] # => false
116
137
  config[:project_id] # => nil
117
138
  config[:enable_graphql] # => false
139
+ ```
140
+
141
+ #### .dig
118
142
 
119
- # get option value in Hash#dig manner (and fail when the required key does not exist)
143
+ ```ruby
144
+ # get option value in Hash#dig manner (and fail when the required key does not exist);
120
145
  config.dig(:vendor_api, :host) # => 'app.service.com' # (key exists)
121
146
  config.dig(:vendor_api, :port) # => Qonfig::UnknownSettingError # (key does not exist)
147
+ ```
122
148
 
123
- # get a hash slice of setting options (and fail when the required key does not exist)
149
+ #### .slice
150
+
151
+ ```ruby
152
+ # get a hash slice of setting options (and fail when the required key does not exist);
124
153
  config.slice(:vendor_api) # => { 'vendor_api' => { 'host' => 'app_service', 'user' => 'test_user' } }
125
154
  config.slice(:vendor_api, :user) # => { 'user' => 'test_user' }
126
155
  config.slice(:project_api) # => Qonfig::UnknownSettingError # (key does not exist)
127
156
  config.slice(:vendor_api, :port) # => Qonfig::UnknownSettingError # (key does not exist)
157
+ ```
158
+
159
+ #### .slice_value
160
+
161
+ ```ruby
162
+ # get value from the slice of setting options using the given key set
163
+ # (and fail when the required key does not exist) (works in slice manner);
128
164
 
129
- # get value from the slice of setting options using the given key set (and fail when the required key does not exist) (works in slice manner)
130
165
  config.slice_value(:vendor_api) # => { 'host' => 'app_service', 'user' => 'test_user' }
131
166
  config.slice_value(:vendor_api, :user) # => 'test_user'
132
167
  config.slice_value(:project_api) # => Qonfig::UnknownSettingError # (key does not exist)
133
168
  config.slice_value(:vendor_api, :port) # => Qonfig::UnknownSettingError # (key does not exist)
134
169
  ```
135
170
 
171
+ #### .subset
172
+
173
+ ```ruby
174
+ # - get a subset (a set of sets) of config settings represented as a hash;
175
+ # - each key (or key set) represents a requirement of a certain setting key;
176
+
177
+ config.subet(:vendor_api, :enable_graphql)
178
+ # => { 'vendor_api' => { 'user' => ..., 'host' => ... }, 'enable_graphql' => false }
179
+
180
+ config.subset(:project_id, [:vendor_api, :host], [:credentials, :user, :login])
181
+ # => { 'project_id' => nil, 'host' => 'app.service.com', 'login' => 'D@iVeR' }
182
+ ```
183
+
136
184
  ---
137
185
 
138
186
  ### Configuration
@@ -407,6 +455,20 @@ GeneralApplication.config.to_h
407
455
  # and etc... (all Qonfig-related features)
408
456
  ```
409
457
 
458
+ ### Instantiation without class definition
459
+
460
+ ```ruby
461
+ config = Qonfig::DataSet.build do
462
+ setting :user, 'D@iVeR'
463
+ setting :password, 'test123'
464
+ end
465
+
466
+ config.is_a?(Qonfig::DataSet) # => true
467
+
468
+ config.settings.user # => 'D@iVeR'
469
+ config.settings.password # => 'test123'
470
+ ```
471
+
410
472
  ---
411
473
 
412
474
  ## Interaction
@@ -12,6 +12,17 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
12
12
  # @since 0.13.0
13
13
  extend Qonfig::Validator::DSL
14
14
 
15
+ class << self
16
+ # @param config_klass_definitions [Proc]
17
+ # @return [Qonfig::DataSet]
18
+ #
19
+ # @api public
20
+ # @since 0.16.0
21
+ def build(&config_klass_definitions)
22
+ Class.new(self, &config_klass_definitions).new
23
+ end
24
+ end
25
+
15
26
  # @return [Qonfig::Settings]
16
27
  #
17
28
  # @api private
@@ -164,6 +175,15 @@ class Qonfig::DataSet # rubocop:disable Metrics/ClassLength
164
175
  thread_safe_access { settings.__slice_value__(*keys) }
165
176
  end
166
177
 
178
+ # @param keys [Array<String, Symbol, Array<String, Symbol>>]
179
+ # @return [Hash]
180
+ #
181
+ # @api private
182
+ # @since 0.16.0
183
+ def subset(*keys)
184
+ thread_safe_access { settings.__subset__(*keys) }
185
+ end
186
+
167
187
  # @return [void]
168
188
  #
169
189
  # @api public
@@ -176,6 +176,15 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
176
176
  __lock__.thread_safe_access { __deep_slice_value__(*keys) }
177
177
  end
178
178
 
179
+ # @param keys [Array<String, Symbol, Array<String, Symbol>>]
180
+ # @return [Hash]
181
+ #
182
+ # @api private
183
+ # @since 0.16.0
184
+ def __subset__(*keys)
185
+ __lock__.thread_safe_access { __deep_subset__(*keys) }
186
+ end
187
+
179
188
  # @option transform_key [Proc]
180
189
  # @option transform_value [Proc]
181
190
  # @return [Hash]
@@ -467,6 +476,34 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
467
476
  __deep_slice__(*keys)[required_key]
468
477
  end
469
478
 
479
+ # @param keys [Array<String, Symbol, Array<String, Symbol>>]
480
+ # @return [Hash]
481
+ #
482
+ # @api private
483
+ # @since 0.16.0
484
+ def __deep_subset__(*keys)
485
+ {}.tap do |result|
486
+ keys.each do |key_set|
487
+ required_keys =
488
+ case key_set
489
+ when String, Symbol
490
+ # TODO: support for patterns
491
+ __indifferently_accessable_option_key__(key_set)
492
+ when Array
493
+ key_set.map(&method(:__indifferently_accessable_option_key__))
494
+ else
495
+ raise(
496
+ Qonfig::ArgumentError,
497
+ 'All setting keys should be a symbol/string or an array of symbols/strings!'
498
+ )
499
+ end
500
+
501
+ required_options = __deep_slice__(*required_keys)
502
+ result.merge!(required_options)
503
+ end
504
+ end
505
+ end
506
+
470
507
  # @param options_part [Hash]
471
508
  # @option transform_key [Proc]
472
509
  # @option transform_value [Proc]
@@ -5,5 +5,5 @@ module Qonfig
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.15.0'
8
+ VERSION = '0.16.0'
9
9
  end
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.15.0
4
+ version: 0.16.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: 2019-09-02 00:00:00.000000000 Z
11
+ date: 2019-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls