qonfig 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/CHANGELOG.md +29 -0
- data/README.md +318 -21
- data/Rakefile +1 -1
- data/lib/qonfig.rb +3 -0
- data/lib/qonfig/compacted.rb +98 -0
- data/lib/qonfig/compacted/constructor.rb +110 -0
- data/lib/qonfig/data_set.rb +83 -42
- data/lib/qonfig/data_set/class_builder.rb +0 -13
- data/lib/qonfig/dsl.rb +13 -7
- data/lib/qonfig/dsl/inheritance.rb +20 -0
- data/lib/qonfig/imports/abstract.rb +22 -1
- data/lib/qonfig/imports/direct_key.rb +25 -6
- data/lib/qonfig/imports/dsl.rb +6 -2
- data/lib/qonfig/imports/export.rb +17 -5
- data/lib/qonfig/imports/general.rb +48 -9
- data/lib/qonfig/imports/mappings.rb +23 -4
- data/lib/qonfig/loaders/basic.rb +1 -1
- data/lib/qonfig/plugins/pretty_print.rb +3 -0
- data/lib/qonfig/plugins/pretty_print/compacted.rb +9 -0
- data/lib/qonfig/plugins/pretty_print/data_set.rb +3 -2
- data/lib/qonfig/plugins/pretty_print/mixin.rb +74 -15
- data/lib/qonfig/plugins/pretty_print/settings.rb +9 -0
- data/lib/qonfig/plugins/toml/data_set.rb +4 -2
- data/lib/qonfig/settings.rb +28 -1
- data/lib/qonfig/settings/builder.rb +27 -3
- data/lib/qonfig/settings/callbacks.rb +2 -0
- data/lib/qonfig/settings/callbacks/validation.rb +30 -0
- data/lib/qonfig/settings/key_matcher.rb +8 -0
- data/lib/qonfig/version.rb +1 -1
- metadata +8 -2
data/lib/qonfig/loaders/basic.rb
CHANGED
@@ -8,9 +8,12 @@ class Qonfig::Plugins::PrettyPrint < Qonfig::Plugins::Abstract
|
|
8
8
|
#
|
9
9
|
# @api private
|
10
10
|
# @since 0.19.0
|
11
|
+
# @version 0.21.0
|
11
12
|
def install!
|
12
13
|
require_relative 'pretty_print/mixin'
|
13
14
|
require_relative 'pretty_print/data_set'
|
15
|
+
require_relative 'pretty_print/settings'
|
16
|
+
require_relative 'pretty_print/compacted'
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
@@ -2,21 +2,80 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.19.0
|
5
|
-
|
6
|
-
# @
|
7
|
-
# @
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
pp.
|
18
|
-
pp.
|
19
|
-
|
5
|
+
class Qonfig::Plugins::PrettyPrint
|
6
|
+
# @api private
|
7
|
+
# @since 0.21.0
|
8
|
+
module DataSetMixin
|
9
|
+
# @param pp [?] Suitable for Ruby's PP module
|
10
|
+
# @return [void]
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
# @since 0.19.0
|
14
|
+
def pretty_print(pp)
|
15
|
+
pp.object_address_group(self) do
|
16
|
+
pp.seplist(keys, proc { pp.text(',') }) do |key|
|
17
|
+
pp.breakable(' ')
|
18
|
+
pp.group(1) do
|
19
|
+
pp.text(key)
|
20
|
+
pp.text(':')
|
21
|
+
pp.breakable
|
22
|
+
pp.pp(self[key])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @api private
|
30
|
+
# @since 0.21.0
|
31
|
+
module CompactedConfigMixin
|
32
|
+
# @param pp [?] Suitable for Ruby's PP module
|
33
|
+
# @return [void]
|
34
|
+
#
|
35
|
+
# @api public
|
36
|
+
# @since 0.21.0
|
37
|
+
def pretty_print(pp)
|
38
|
+
pp.object_address_group(self) do
|
39
|
+
pp.seplist(@____data_set____.keys, ::Kernel.proc { pp.text(',') }) do |key|
|
40
|
+
pp.breakable(' ')
|
41
|
+
pp.group(1) do
|
42
|
+
pp.text(key)
|
43
|
+
pp.text(':')
|
44
|
+
pp.breakable
|
45
|
+
pp.pp(@____data_set____[key])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Integer]
|
52
|
+
#
|
53
|
+
# @see Object#object_id
|
54
|
+
# @see BasicObject#__id__
|
55
|
+
#
|
56
|
+
# @api public
|
57
|
+
# @since 0.21.0
|
58
|
+
alias_method :object_id, :__id__
|
59
|
+
end
|
60
|
+
|
61
|
+
# @api private
|
62
|
+
# @since 0.21.0
|
63
|
+
module SettingsMixin
|
64
|
+
# @param pp [?] Suitable for Ruby's PP module
|
65
|
+
# @return [void]
|
66
|
+
#
|
67
|
+
# @api public
|
68
|
+
# @since 0.21.0
|
69
|
+
def pretty_print(pp)
|
70
|
+
pp.object_address_group(self) do
|
71
|
+
pp.seplist(__keys__, proc { pp.text(',') }) do |key|
|
72
|
+
pp.breakable(' ')
|
73
|
+
pp.group(1) do
|
74
|
+
pp.text(key)
|
75
|
+
pp.text(':')
|
76
|
+
pp.breakable
|
77
|
+
pp.pp(self[key])
|
78
|
+
end
|
20
79
|
end
|
21
80
|
end
|
22
81
|
end
|
@@ -20,13 +20,15 @@ class Qonfig::DataSet
|
|
20
20
|
# @param file_path [String]
|
21
21
|
# @option strict [Boolean]
|
22
22
|
# @option expose [NilClass, String, Symbol] Environment key
|
23
|
+
# @param configuration [Block]
|
23
24
|
# @return [void]
|
24
25
|
#
|
25
26
|
# @see Qonfig::DataSet#load_from_file
|
26
27
|
#
|
27
28
|
# @api public
|
28
29
|
# @since 0.17.0
|
29
|
-
|
30
|
-
|
30
|
+
# @version 0.21.0
|
31
|
+
def load_from_toml(file_path, strict: true, expose: nil, &configuration)
|
32
|
+
load_from_file(file_path, format: :toml, strict: strict, expose: expose, &configuration)
|
31
33
|
end
|
32
34
|
end
|
data/lib/qonfig/settings.rb
CHANGED
@@ -151,8 +151,9 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
151
151
|
#
|
152
152
|
# @api public
|
153
153
|
# @since 0.1.0
|
154
|
+
# @version 0.21.0
|
154
155
|
def []=(key, value)
|
155
|
-
__lock__.thread_safe_access {
|
156
|
+
__lock__.thread_safe_access { __assign_value__(key, value) }
|
156
157
|
end
|
157
158
|
|
158
159
|
# @param settings_map [Hash]
|
@@ -489,6 +490,32 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
489
490
|
__options__[key]
|
490
491
|
end
|
491
492
|
|
493
|
+
# @param key [String, Symbol]
|
494
|
+
# @param value [Any]
|
495
|
+
# @return [void]
|
496
|
+
#
|
497
|
+
# @api private
|
498
|
+
# @since 0.21.0
|
499
|
+
# rubocop:disable Naming/RescuedExceptionsVariableName
|
500
|
+
def __assign_value__(key, value)
|
501
|
+
key = __indifferently_accessable_option_key__(key)
|
502
|
+
__set_value__(key, value)
|
503
|
+
rescue Qonfig::UnknownSettingError => initial_error
|
504
|
+
key_set = __parse_dot_notated_key__(key)
|
505
|
+
|
506
|
+
# NOTE: key is not dot-notaed and original key does not exist
|
507
|
+
raise(initial_error) if key_set.size == 1
|
508
|
+
|
509
|
+
begin
|
510
|
+
setting_value = __get_value__(key_set.first)
|
511
|
+
required_key = key_set[1..-1].join(DOT_NOTATION_SEPARATOR)
|
512
|
+
setting_value[required_key] = value # NOTE: pseudo-recoursive assignment
|
513
|
+
rescue Qonfig::UnknownSettingError
|
514
|
+
raise(initial_error)
|
515
|
+
end
|
516
|
+
end
|
517
|
+
# rubocop:enable Naming/RescuedExceptionsVariableName
|
518
|
+
|
492
519
|
# @param key [String, Symbol]
|
493
520
|
# @param value [Object]
|
494
521
|
# @return [void]
|
@@ -4,6 +4,23 @@
|
|
4
4
|
# @since 0.2.0
|
5
5
|
module Qonfig::Settings::Builder
|
6
6
|
class << self
|
7
|
+
# @param data_set [Qonfig::DataSet]
|
8
|
+
# @param assignements [Block]
|
9
|
+
# @yield [settings, validator]
|
10
|
+
# @yieldparam settings [Qonfig::DataSet::Settings]
|
11
|
+
# @yieldparam validator [Qonfig::Validation::Validators::Composite]
|
12
|
+
# @return [void]
|
13
|
+
#
|
14
|
+
# @api private
|
15
|
+
# @since 0.21.0
|
16
|
+
def build(data_set, &assignements)
|
17
|
+
validator = build_validator(data_set)
|
18
|
+
settings = build_definitions(data_set)
|
19
|
+
yield(settings, validator)
|
20
|
+
validator.validate!
|
21
|
+
build_state(data_set)
|
22
|
+
end
|
23
|
+
|
7
24
|
# @param data_set [Qonfig::DataSet]
|
8
25
|
# @return [Qonfig::Settings]
|
9
26
|
#
|
@@ -30,16 +47,23 @@ module Qonfig::Settings::Builder
|
|
30
47
|
|
31
48
|
private
|
32
49
|
|
50
|
+
# @param data_set [Qonfig::DataSet]
|
51
|
+
# @return [Qonfig::Validation::Validators::Composite]
|
52
|
+
#
|
53
|
+
# @api private
|
54
|
+
# @since 0.21.0
|
55
|
+
def build_validator(data_set)
|
56
|
+
Qonfig::Validation::Validators::Composite.new(data_set)
|
57
|
+
end
|
58
|
+
|
33
59
|
# @param data_set [Qonfig::DataSet]
|
34
60
|
# @return [Qonfig::Settings::Callbacks]
|
35
61
|
#
|
36
62
|
# @api private
|
37
63
|
# @since 0.13.0
|
38
64
|
def build_mutation_callbacks(data_set)
|
39
|
-
validation_callback = proc { data_set.validate! }
|
40
|
-
|
41
65
|
Qonfig::Settings::Callbacks.new.tap do |callbacks|
|
42
|
-
callbacks.add(
|
66
|
+
callbacks.add(Qonfig::Settings::Callbacks::Validation.new(data_set))
|
43
67
|
end
|
44
68
|
end
|
45
69
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.21.0
|
5
|
+
class Qonfig::Settings::Callbacks::Validation
|
6
|
+
# @param data_set [Qonfig::DataSet]
|
7
|
+
# @return [void]
|
8
|
+
#
|
9
|
+
# @api private
|
10
|
+
# @since 0.21.0
|
11
|
+
def initialize(data_set)
|
12
|
+
@data_set = data_set
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [void]
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
# @since 0.21.0
|
19
|
+
def call
|
20
|
+
data_set.validate!
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# @return [Qonfig::DataSet]
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
# @since 0.21.0
|
29
|
+
attr_reader :data_set
|
30
|
+
end
|
@@ -61,6 +61,14 @@ class Qonfig::Settings::KeyMatcher
|
|
61
61
|
@pattern_matcher = build_pattern_matcher(scope_pattern)
|
62
62
|
end
|
63
63
|
|
64
|
+
# @return [Boolean]
|
65
|
+
#
|
66
|
+
# @api private
|
67
|
+
# @since 0.21.0
|
68
|
+
def generic?
|
69
|
+
scope_pattern == GENERIC_PART_PATTERN || scope_pattern == INFINITE_PART_PATTERN
|
70
|
+
end
|
71
|
+
|
64
72
|
# @param setting_key_pattern [String]
|
65
73
|
# @return [Boolean]
|
66
74
|
#
|
data/lib/qonfig/version.rb
CHANGED
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.
|
4
|
+
version: 0.21.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-11
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -154,11 +154,14 @@ files:
|
|
154
154
|
- lib/qonfig/commands/instantiation.rb
|
155
155
|
- lib/qonfig/commands/instantiation/freeze_state.rb
|
156
156
|
- lib/qonfig/commands/instantiation/values_file.rb
|
157
|
+
- lib/qonfig/compacted.rb
|
158
|
+
- lib/qonfig/compacted/constructor.rb
|
157
159
|
- lib/qonfig/configurable.rb
|
158
160
|
- lib/qonfig/data_set.rb
|
159
161
|
- lib/qonfig/data_set/class_builder.rb
|
160
162
|
- lib/qonfig/data_set/lock.rb
|
161
163
|
- lib/qonfig/dsl.rb
|
164
|
+
- lib/qonfig/dsl/inheritance.rb
|
162
165
|
- lib/qonfig/errors.rb
|
163
166
|
- lib/qonfig/imports.rb
|
164
167
|
- lib/qonfig/imports/abstract.rb
|
@@ -177,8 +180,10 @@ files:
|
|
177
180
|
- lib/qonfig/plugins/abstract.rb
|
178
181
|
- lib/qonfig/plugins/access_mixin.rb
|
179
182
|
- lib/qonfig/plugins/pretty_print.rb
|
183
|
+
- lib/qonfig/plugins/pretty_print/compacted.rb
|
180
184
|
- lib/qonfig/plugins/pretty_print/data_set.rb
|
181
185
|
- lib/qonfig/plugins/pretty_print/mixin.rb
|
186
|
+
- lib/qonfig/plugins/pretty_print/settings.rb
|
182
187
|
- lib/qonfig/plugins/registry.rb
|
183
188
|
- lib/qonfig/plugins/toml.rb
|
184
189
|
- lib/qonfig/plugins/toml/commands/definition/expose_toml.rb
|
@@ -194,6 +199,7 @@ files:
|
|
194
199
|
- lib/qonfig/settings.rb
|
195
200
|
- lib/qonfig/settings/builder.rb
|
196
201
|
- lib/qonfig/settings/callbacks.rb
|
202
|
+
- lib/qonfig/settings/callbacks/validation.rb
|
197
203
|
- lib/qonfig/settings/key_guard.rb
|
198
204
|
- lib/qonfig/settings/key_matcher.rb
|
199
205
|
- lib/qonfig/settings/lock.rb
|