qonfig 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +168 -29
- data/lib/qonfig/commands/definition/re_define_option.rb +60 -0
- data/lib/qonfig/commands/definition.rb +1 -0
- data/lib/qonfig/data_set/class_builder.rb +2 -0
- data/lib/qonfig/data_set.rb +5 -5
- data/lib/qonfig/dsl.rb +101 -9
- data/lib/qonfig/errors.rb +14 -8
- data/lib/qonfig/plugins/toml/commands/{expose_toml.rb → definition/expose_toml.rb} +5 -1
- data/lib/qonfig/plugins/toml/commands/{load_from_toml.rb → definition/load_from_toml.rb} +5 -1
- data/lib/qonfig/plugins/toml/dsl.rb +8 -2
- data/lib/qonfig/plugins/toml.rb +2 -2
- data/lib/qonfig/settings.rb +4 -2
- data/lib/qonfig/{validator/builder → validation/building/instance_builder}/attribute_consistency.rb +14 -14
- data/lib/qonfig/{validator/builder.rb → validation/building/instance_builder.rb} +55 -30
- data/lib/qonfig/validation/building/predefined_builder.rb +86 -0
- data/lib/qonfig/validation/building.rb +8 -0
- data/lib/qonfig/{validator/collection.rb → validation/collections/instance_collection.rb} +16 -14
- data/lib/qonfig/validation/collections/predefined_registry.rb +145 -0
- data/lib/qonfig/validation/collections.rb +8 -0
- data/lib/qonfig/validation/predefinition_mixin.rb +15 -0
- data/lib/qonfig/{validator → validation/validators}/basic.rb +9 -9
- data/lib/qonfig/{validator.rb → validation/validators/composite.rb} +8 -16
- data/lib/qonfig/{validator → validation/validators}/method_based.rb +6 -6
- data/lib/qonfig/{validator/predefined/common.rb → validation/validators/predefined.rb} +7 -7
- data/lib/qonfig/{validator → validation/validators}/proc_based.rb +6 -6
- data/lib/qonfig/validation/validators.rb +11 -0
- data/lib/qonfig/validation.rb +10 -0
- data/lib/qonfig/version.rb +1 -1
- data/lib/qonfig.rb +34 -1
- data/qonfig.gemspec +1 -1
- metadata +23 -26
- data/lib/qonfig/validator/dsl.rb +0 -59
- data/lib/qonfig/validator/predefined/registry.rb +0 -81
- data/lib/qonfig/validator/predefined/registry_control_mixin.rb +0 -44
- data/lib/qonfig/validator/predefined.rb +0 -41
data/lib/qonfig/dsl.rb
CHANGED
@@ -2,27 +2,36 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
-
|
5
|
+
# @version 0.20.0
|
6
|
+
module Qonfig::DSL # rubocop:disable Metrics/ModuleLength
|
6
7
|
class << self
|
7
8
|
# @param child_klass [Qonfig::DataSet]
|
8
9
|
# @return [void]
|
9
10
|
#
|
11
|
+
# @see Qonfig::DataSet::ClassBuilder
|
12
|
+
#
|
10
13
|
# @api private
|
11
14
|
# @since 0.1.0
|
12
|
-
# @version 0.
|
15
|
+
# @version 0.20.0
|
16
|
+
# rubocop:disable Metrics/LineLength, Metrics/AbcSize
|
13
17
|
def extended(child_klass)
|
14
18
|
child_klass.instance_variable_set(:@definition_commands, Qonfig::CommandSet.new)
|
15
19
|
child_klass.instance_variable_set(:@instance_commands, Qonfig::CommandSet.new)
|
20
|
+
child_klass.instance_variable_set(:@predefined_validators, Qonfig::Validation::Collections::PredefinedRegistry.new)
|
21
|
+
child_klass.instance_variable_set(:@validators, Qonfig::Validation::Collections::InstanceCollection.new)
|
16
22
|
|
17
23
|
child_klass.singleton_class.prepend(Module.new do
|
18
24
|
def inherited(child_klass)
|
19
25
|
child_klass.instance_variable_set(:@definition_commands, Qonfig::CommandSet.new)
|
20
26
|
child_klass.instance_variable_set(:@instance_commands, Qonfig::CommandSet.new)
|
27
|
+
child_klass.instance_variable_set(:@predefined_validators, Qonfig::Validation::Collections::PredefinedRegistry.new)
|
28
|
+
child_klass.instance_variable_set(:@validators, Qonfig::Validation::Collections::InstanceCollection.new)
|
21
29
|
Qonfig::DataSet::ClassBuilder.inherit(base_klass: self, child_klass: child_klass)
|
22
30
|
super
|
23
31
|
end
|
24
32
|
end)
|
25
33
|
end
|
34
|
+
# rubocop:enable Metrics/LineLength, Metrics/AbcSize
|
26
35
|
end
|
27
36
|
|
28
37
|
# @return [Qonfig::CommandSet]
|
@@ -41,13 +50,71 @@ module Qonfig::DSL
|
|
41
50
|
@instance_commands
|
42
51
|
end
|
43
52
|
|
53
|
+
# @return [Qonfig::Validation::Collections::PredefinedRegistry]
|
54
|
+
#
|
55
|
+
# @api private
|
56
|
+
# @since 0.20.0
|
57
|
+
def predefined_validators
|
58
|
+
@predefined_validators
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Qonfig::Validation::Collections::InstanceCollection]
|
62
|
+
#
|
63
|
+
# @api private
|
64
|
+
# @since 0.20.0
|
65
|
+
def validators
|
66
|
+
@validators
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param setting_key_pattern [String, Symbol, NilClass]
|
70
|
+
# @param predefined [String, Symbol]
|
71
|
+
# @option by [String, Symbol, NilClass]
|
72
|
+
# @option stict [Boolean]
|
73
|
+
# @param custom_validation [Proc]
|
74
|
+
# @return [void]
|
75
|
+
#
|
76
|
+
# @see Qonfig::Validation::Building::InstanceBuilder
|
77
|
+
#
|
78
|
+
# @api public
|
79
|
+
# @since 0.20.0
|
80
|
+
def validate(
|
81
|
+
setting_key_pattern = nil,
|
82
|
+
predefined = nil,
|
83
|
+
strict: false,
|
84
|
+
by: nil,
|
85
|
+
&custom_validation
|
86
|
+
)
|
87
|
+
validators << Qonfig::Validation::Building::InstanceBuilder.build(
|
88
|
+
self,
|
89
|
+
setting_key_pattern: setting_key_pattern,
|
90
|
+
predefined_validator: predefined,
|
91
|
+
runtime_validation_method: by,
|
92
|
+
strict: strict,
|
93
|
+
validation_logic: custom_validation
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param name [String, Symbol]
|
98
|
+
# @param validation_logic [Block]
|
99
|
+
# @return [void]
|
100
|
+
#
|
101
|
+
# @see Qonfig::Validation::Building::PredefinedBuilder
|
102
|
+
#
|
103
|
+
# @api public
|
104
|
+
# @since 0.20.0
|
105
|
+
def define_validator(name, &validation_logic)
|
106
|
+
Qonfig::Validation::Building::PredefinedBuilder.build(
|
107
|
+
name, validation_logic, predefined_validators
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
44
111
|
# @param key [Symbol, String]
|
45
112
|
# @param initial_value [Object]
|
46
113
|
# @param nested_settings [Proc]
|
47
114
|
# @return [void]
|
48
115
|
#
|
49
|
-
# @see Qonfig::Commands::AddNestedOption
|
50
|
-
# @see Qonfig::Commands::AddOption
|
116
|
+
# @see Qonfig::Commands::Definition::AddNestedOption
|
117
|
+
# @see Qonfig::Commands::Definition::AddOption
|
51
118
|
#
|
52
119
|
# @api public
|
53
120
|
# @since 0.1.0
|
@@ -59,10 +126,25 @@ module Qonfig::DSL
|
|
59
126
|
end
|
60
127
|
end
|
61
128
|
|
129
|
+
# @param key [Symbol, String]
|
130
|
+
# @param initial_value [Object]
|
131
|
+
# @param nested_settings [Proc]
|
132
|
+
# @return [void]
|
133
|
+
#
|
134
|
+
# @see Qonfig::Comamnds::Definition::ReDefineOption
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
# @since 0.20.0
|
138
|
+
def re_setting(key, initial_value = nil, &nested_settings)
|
139
|
+
definition_commands << Qonfig::Commands::Definition::ReDefineOption.new(
|
140
|
+
key, initial_value, nested_settings
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
62
144
|
# @param data_set_klass [Class<Qonfig::DataSet>]
|
63
145
|
# @return [void]
|
64
146
|
#
|
65
|
-
# @see Qonfig::Comamnds::Compose
|
147
|
+
# @see Qonfig::Comamnds::Definition::Compose
|
66
148
|
#
|
67
149
|
# @api private
|
68
150
|
# @sine 0.1.0
|
@@ -74,7 +156,7 @@ module Qonfig::DSL
|
|
74
156
|
# @option strict [Boolean]
|
75
157
|
# @return [void]
|
76
158
|
#
|
77
|
-
# @see Qonfig::Commands::LoadFromYAML
|
159
|
+
# @see Qonfig::Commands::Definition::LoadFromYAML
|
78
160
|
#
|
79
161
|
# @api public
|
80
162
|
# @since 0.2.0
|
@@ -86,7 +168,7 @@ module Qonfig::DSL
|
|
86
168
|
|
87
169
|
# @return [void]
|
88
170
|
#
|
89
|
-
# @see Qonfig::Commands::LoadFromSelf
|
171
|
+
# @see Qonfig::Commands::Definition::LoadFromSelf
|
90
172
|
#
|
91
173
|
# @api public
|
92
174
|
# @since 0.2.0
|
@@ -102,7 +184,7 @@ module Qonfig::DSL
|
|
102
184
|
# @option prefix [NilClass, String, Regexp]
|
103
185
|
# @return [void]
|
104
186
|
#
|
105
|
-
# @see Qonfig::Commands::LoadFromENV
|
187
|
+
# @see Qonfig::Commands::Definition::LoadFromENV
|
106
188
|
#
|
107
189
|
# @api public
|
108
190
|
# @since 0.2.0
|
@@ -118,6 +200,8 @@ module Qonfig::DSL
|
|
118
200
|
# @option strict [Boolean]
|
119
201
|
# @return [void]
|
120
202
|
#
|
203
|
+
# @see Qonfig::Commands::Definition::LoadFromJSON
|
204
|
+
#
|
121
205
|
# @api public
|
122
206
|
# @since 0.5.0
|
123
207
|
def load_from_json(file_path, strict: true)
|
@@ -130,6 +214,8 @@ module Qonfig::DSL
|
|
130
214
|
# @option env [Symbol, String]
|
131
215
|
# @return [void]
|
132
216
|
#
|
217
|
+
# @see Qonfig::Commands::Definition::ExposeYAML
|
218
|
+
#
|
133
219
|
# @api public
|
134
220
|
# @since 0.7.0
|
135
221
|
def expose_yaml(file_path, strict: true, via:, env:)
|
@@ -144,6 +230,8 @@ module Qonfig::DSL
|
|
144
230
|
# @option env [Symbol, String]
|
145
231
|
# @return [void]
|
146
232
|
#
|
233
|
+
# @see Qonfig::Commands::Definition::ExposeJSON
|
234
|
+
#
|
147
235
|
# @api public
|
148
236
|
# @since 0.14.0
|
149
237
|
def expose_json(file_path, strict: true, via:, env:)
|
@@ -155,7 +243,7 @@ module Qonfig::DSL
|
|
155
243
|
# @option env [Symbol, String]
|
156
244
|
# @return [void]
|
157
245
|
#
|
158
|
-
# @see Qonfig::Commands::
|
246
|
+
# @see Qonfig::Commands::Definition::ExposeSelf
|
159
247
|
#
|
160
248
|
# @api public
|
161
249
|
# @since 0.14.0
|
@@ -173,6 +261,8 @@ module Qonfig::DSL
|
|
173
261
|
# @option expose [NilClass, String, Symbol] Environment key
|
174
262
|
# @return [void]
|
175
263
|
#
|
264
|
+
# @see Qonfig::Commands::Instantiation::ValuesFile
|
265
|
+
#
|
176
266
|
# @api public
|
177
267
|
# @since 0.17.0
|
178
268
|
def values_file(file_path, format: :dynamic, strict: false, expose: nil)
|
@@ -185,6 +275,8 @@ module Qonfig::DSL
|
|
185
275
|
|
186
276
|
# @return [void]
|
187
277
|
#
|
278
|
+
# @see Qonfig::Commands::Instantiation::FreezeState
|
279
|
+
#
|
188
280
|
# @api public
|
189
281
|
# @since 0.19.0
|
190
282
|
def freeze_state!
|
data/lib/qonfig/errors.rb
CHANGED
@@ -9,21 +9,26 @@ module Qonfig
|
|
9
9
|
# @since 0.1.0
|
10
10
|
ArgumentError = Class.new(ArgumentError)
|
11
11
|
|
12
|
-
# @see Qonfig::
|
13
|
-
# @see Qonfig::
|
12
|
+
# @see Qonfig::Validation::Validators::MethodBased
|
13
|
+
# @see Qonfig::Validation::Validators::ProcBased
|
14
|
+
# @see Qonfig::Validation::Validators::Predefined
|
14
15
|
#
|
15
16
|
# @api public
|
16
17
|
# @since 0.13.0
|
17
|
-
|
18
|
+
ValidationError = Class.new(Error)
|
18
19
|
|
19
|
-
# @see Qonfig::
|
20
|
-
# @see Qonfig::
|
21
|
-
# @see Qonfig::Validator::ProcBased
|
22
|
-
# @see Qonfig::Validator::Predefined::Common
|
20
|
+
# @see Qonfig::Validation::Building::InstanceBuilder::AttributeConsistency
|
21
|
+
# @see Qonfig::Validation::Building::PredefinedBuilder
|
23
22
|
#
|
24
23
|
# @api public
|
25
24
|
# @since 0.13.0
|
26
|
-
|
25
|
+
ValidatorArgumentError = Class.new(ArgumentError)
|
26
|
+
|
27
|
+
# @see Qonfig::Validation::Collections::PredefinedRegistry
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
# @since 0.20.0
|
31
|
+
ValidatorNotFoundError = Class.new(ValidatorArgumentError)
|
27
32
|
|
28
33
|
# @api public
|
29
34
|
# @since 0.12.0
|
@@ -63,6 +68,7 @@ module Qonfig
|
|
63
68
|
# @see Qonfig::Settings::KeyGuard
|
64
69
|
# @see Qonfig::Commands::Definition::AddOption
|
65
70
|
# @see Qonfig::Commands::Definition::AddNestedOption
|
71
|
+
# @see Qonfig::Commands::Definition::ReDefineOption
|
66
72
|
#
|
67
73
|
# @api public
|
68
74
|
# @since 0.2.0
|
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.12.0
|
5
|
-
|
5
|
+
# @version 0.20.0
|
6
|
+
class Qonfig::Commands::Definition::ExposeTOML < Qonfig::Commands::Base
|
7
|
+
# @since 0.20.0
|
8
|
+
self.inheritable = true
|
9
|
+
|
6
10
|
# @return [Hash]
|
7
11
|
#
|
8
12
|
# @api private
|
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.12.0
|
5
|
-
|
5
|
+
# @version 0.20.0
|
6
|
+
class Qonfig::Commands::Definition::LoadFromTOML < Qonfig::Commands::Base
|
7
|
+
# @since 0.20.0
|
8
|
+
self.inheritable = true
|
9
|
+
|
6
10
|
# @return [String]
|
7
11
|
#
|
8
12
|
# @api private
|
@@ -7,10 +7,13 @@ module Qonfig::DSL
|
|
7
7
|
# @option strict [Boolean]
|
8
8
|
# @return [void]
|
9
9
|
#
|
10
|
+
# @see Qonfig::Commands::Definition::LoadFromTOML
|
11
|
+
#
|
10
12
|
# @api public
|
11
13
|
# @since 0.12.0
|
14
|
+
# @version 0.20.0
|
12
15
|
def load_from_toml(file_path, strict: true)
|
13
|
-
definition_commands << Qonfig::Commands::LoadFromTOML.new(
|
16
|
+
definition_commands << Qonfig::Commands::Definition::LoadFromTOML.new(
|
14
17
|
file_path, strict: strict
|
15
18
|
)
|
16
19
|
end
|
@@ -21,10 +24,13 @@ module Qonfig::DSL
|
|
21
24
|
# @option env [Symbol, String]
|
22
25
|
# @return [void]
|
23
26
|
#
|
27
|
+
# @see Qonfig::Commands::Definition::ExposeTOML
|
28
|
+
#
|
24
29
|
# @api public
|
25
30
|
# @since 0.12.0
|
31
|
+
# @version 0.20.0
|
26
32
|
def expose_toml(file_path, strict: true, via:, env:)
|
27
|
-
definition_commands << Qonfig::Commands::ExposeTOML.new(
|
33
|
+
definition_commands << Qonfig::Commands::Definition::ExposeTOML.new(
|
28
34
|
file_path, strict: strict, via: via, env: env
|
29
35
|
)
|
30
36
|
end
|
data/lib/qonfig/plugins/toml.rb
CHANGED
@@ -20,8 +20,8 @@ class Qonfig::Plugins::TOML < Qonfig::Plugins::Abstract
|
|
20
20
|
require_relative 'toml/loaders/toml'
|
21
21
|
require_relative 'toml/loaders/dynamic'
|
22
22
|
require_relative 'toml/uploaders/toml'
|
23
|
-
require_relative 'toml/commands/load_from_toml'
|
24
|
-
require_relative 'toml/commands/expose_toml'
|
23
|
+
require_relative 'toml/commands/definition/load_from_toml'
|
24
|
+
require_relative 'toml/commands/definition/expose_toml'
|
25
25
|
require_relative 'toml/data_set'
|
26
26
|
require_relative 'toml/dsl'
|
27
27
|
end
|
data/lib/qonfig/settings.rb
CHANGED
@@ -82,18 +82,20 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
82
82
|
|
83
83
|
# @param key [Symbol, String]
|
84
84
|
# @param value [Object]
|
85
|
+
# @option with_redefinition [Boolean]
|
85
86
|
# @return [void]
|
86
87
|
#
|
87
88
|
# @api private
|
88
89
|
# @since 0.1.0
|
89
|
-
|
90
|
+
# @version 0.20.0
|
91
|
+
def __define_setting__(key, value, with_redefinition: false) # rubocop:disable Metrics/AbcSize
|
90
92
|
__lock__.thread_safe_definition do
|
91
93
|
key = __indifferently_accessable_option_key__(key)
|
92
94
|
|
93
95
|
__prevent_core_method_intersection__(key)
|
94
96
|
|
95
97
|
case
|
96
|
-
when !__options__.key?(key)
|
98
|
+
when with_redefinition || !__options__.key?(key)
|
97
99
|
__options__[key] = value
|
98
100
|
when __is_a_setting__(__options__[key]) && __is_a_setting__(value)
|
99
101
|
__options__[key].__append_settings__(value)
|
data/lib/qonfig/{validator/builder → validation/building/instance_builder}/attribute_consistency.rb
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api private
|
4
|
-
# @since 0.
|
4
|
+
# @since 0.20.0
|
5
5
|
# rubocop:disable Metrics/ClassLength
|
6
|
-
class Qonfig::
|
6
|
+
class Qonfig::Validation::Building::InstanceBuilder::AttributesConsistency
|
7
7
|
class << self
|
8
8
|
# @param setting_key_pattern [String, Symbol, NilClass]
|
9
9
|
# @param predefined_validator [String, Symbol, NilClass]
|
@@ -13,7 +13,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
13
13
|
# @return [void]
|
14
14
|
#
|
15
15
|
# @api private
|
16
|
-
# @since 0.
|
16
|
+
# @since 0.20.0
|
17
17
|
def check!(
|
18
18
|
setting_key_pattern,
|
19
19
|
predefined_validator,
|
@@ -38,7 +38,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
38
38
|
# @return [void]
|
39
39
|
#
|
40
40
|
# @api private
|
41
|
-
# @since 0.
|
41
|
+
# @since 0.20.0
|
42
42
|
def initialize(
|
43
43
|
setting_key_pattern,
|
44
44
|
predefined_validator,
|
@@ -58,7 +58,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
58
58
|
# @raise [Qonfig::ValidatorArgumentError]
|
59
59
|
#
|
60
60
|
# @api private
|
61
|
-
# @since 0.
|
61
|
+
# @since 0.20.0
|
62
62
|
def check!
|
63
63
|
consistent_strict_behaviour!
|
64
64
|
consistent_method_choice!
|
@@ -73,19 +73,19 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
73
73
|
# @return [String, Symbol, NilClass]
|
74
74
|
#
|
75
75
|
# @api private
|
76
|
-
# @since 0.
|
76
|
+
# @since 0.20.0
|
77
77
|
attr_reader :setting_key_pattern
|
78
78
|
|
79
79
|
# @return [String, Symbol, NilClass]
|
80
80
|
#
|
81
81
|
# @api private
|
82
|
-
# @since 0.
|
82
|
+
# @since 0.20.0
|
83
83
|
attr_reader :predefined_validator
|
84
84
|
|
85
85
|
# @return [String, Symbol, NilClass]
|
86
86
|
#
|
87
87
|
# @api private
|
88
|
-
# @since 0.
|
88
|
+
# @since 0.20.0
|
89
89
|
attr_reader :runtime_validation_method
|
90
90
|
|
91
91
|
# @return [Boolean]
|
@@ -97,7 +97,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
97
97
|
# @return [Proc, NilClass]
|
98
98
|
#
|
99
99
|
# @api private
|
100
|
-
# @since 0.
|
100
|
+
# @since 0.20.0
|
101
101
|
attr_reader :validation_logic
|
102
102
|
|
103
103
|
# @return [void]
|
@@ -105,7 +105,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
105
105
|
# @raise [Qonfig::ValidatorArgumentError]
|
106
106
|
#
|
107
107
|
# @api private
|
108
|
-
# @since 0.
|
108
|
+
# @since 0.20.0
|
109
109
|
def consistent_method_choice!
|
110
110
|
unless runtime_validation_method || validation_logic || predefined_validator
|
111
111
|
raise(
|
@@ -143,7 +143,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
143
143
|
# @raise [Qonfig::ValidatorArgumentError]
|
144
144
|
#
|
145
145
|
# @api private
|
146
|
-
# @since 0.
|
146
|
+
# @since 0.20.0
|
147
147
|
def consistent_predefined_validator!
|
148
148
|
return if predefined_validator.nil?
|
149
149
|
return if predefined_validator.is_a?(Symbol)
|
@@ -160,7 +160,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
160
160
|
# @raise [Qonfig::ValidatorArgumentError]
|
161
161
|
#
|
162
162
|
# @api private
|
163
|
-
# @since 0.
|
163
|
+
# @since 0.20.0
|
164
164
|
def cosnistent_runtime_validation_method!
|
165
165
|
return if runtime_validation_method.nil?
|
166
166
|
return if runtime_validation_method.is_a?(Symbol)
|
@@ -177,7 +177,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
177
177
|
# @raise [Qonfig::ValidatorArgumentError]
|
178
178
|
#
|
179
179
|
# @api private
|
180
|
-
# @since 0.
|
180
|
+
# @since 0.20.0
|
181
181
|
def consistent_validation_logic!
|
182
182
|
return if validation_logic.nil?
|
183
183
|
return if validation_logic.is_a?(Proc)
|
@@ -195,7 +195,7 @@ class Qonfig::Validator::Builder::AttributeConsistency
|
|
195
195
|
# @raise [Qonfig::ValidatorArgumentError]
|
196
196
|
#
|
197
197
|
# @api private
|
198
|
-
# @since 0.
|
198
|
+
# @since 0.20.0
|
199
199
|
def consistent_setting_key_pattern!
|
200
200
|
return if setting_key_pattern.nil?
|
201
201
|
return if setting_key_pattern.is_a?(Symbol)
|
@@ -1,32 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# @api private
|
4
|
-
# @since 0.
|
5
|
-
class Qonfig::
|
6
|
-
require_relative '
|
4
|
+
# @since 0.20.0
|
5
|
+
class Qonfig::Validation::Building::InstanceBuilder
|
6
|
+
require_relative 'instance_builder/attribute_consistency'
|
7
7
|
|
8
8
|
# @return [NilClass]
|
9
9
|
#
|
10
10
|
# @api private
|
11
|
-
# @since 0.
|
11
|
+
# @since 0.20.0
|
12
12
|
EMPTY_SETTING_KEY_PATTERN = nil
|
13
13
|
|
14
14
|
# @return [NilClass]
|
15
15
|
#
|
16
16
|
# @api private
|
17
|
-
# @since 0.
|
17
|
+
# @since 0.20.0
|
18
18
|
NO_RUNTIME_VALIDATION_METHOD = nil
|
19
19
|
|
20
20
|
# @return [NilClass]
|
21
21
|
#
|
22
22
|
# @api private
|
23
|
-
# @since 0.
|
23
|
+
# @since 0.20.0
|
24
24
|
NO_VALIDATION_LOGIC = nil
|
25
25
|
|
26
26
|
# @return [NilClass]
|
27
27
|
#
|
28
28
|
# @api private
|
29
|
-
# @since 0.
|
29
|
+
# @since 0.20.0
|
30
30
|
NO_PREDEFINED_VALIDATOR = nil
|
31
31
|
|
32
32
|
# @return [Boolean]
|
@@ -36,6 +36,7 @@ class Qonfig::Validator::Builder
|
|
36
36
|
DEFAULT_STRICT_BEHAVIOUR = false
|
37
37
|
|
38
38
|
class << self
|
39
|
+
# @param data_set_klass [Class<Qonfig::DataSet>]
|
39
40
|
# @option setting_key_pattern [String, Symbol, NilClass]
|
40
41
|
# @option predefined_validator [String, Symbol, NilClass]
|
41
42
|
# @option runtime_validation_method [String, Symbol, NilClass]
|
@@ -44,8 +45,9 @@ class Qonfig::Validator::Builder
|
|
44
45
|
# @return [Qonfig::Validator::MethodBased, Qonfig::Validator::ProcBased]
|
45
46
|
#
|
46
47
|
# @api private
|
47
|
-
# @since 0.
|
48
|
+
# @since 0.20.0
|
48
49
|
def build(
|
50
|
+
data_set_klass,
|
49
51
|
setting_key_pattern: EMPTY_SETTING_KEY_PATTERN,
|
50
52
|
runtime_validation_method: NO_RUNTIME_VALIDATION_METHOD,
|
51
53
|
validation_logic: NO_VALIDATION_LOGIC,
|
@@ -53,6 +55,7 @@ class Qonfig::Validator::Builder
|
|
53
55
|
predefined_validator: NO_PREDEFINED_VALIDATOR
|
54
56
|
)
|
55
57
|
new(
|
58
|
+
data_set_klass,
|
56
59
|
setting_key_pattern,
|
57
60
|
predefined_validator,
|
58
61
|
runtime_validation_method,
|
@@ -62,6 +65,7 @@ class Qonfig::Validator::Builder
|
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
68
|
+
# @param data_set_klass [Class<Qonfig::DataSet>]
|
65
69
|
# @param setting_key_pattern [String, Symbol, NilClass]
|
66
70
|
# @param predefined_validator_name [String, Symbol, NilClass]
|
67
71
|
# @param runtime_validation_method [String, Symbol, NilClass]
|
@@ -70,14 +74,16 @@ class Qonfig::Validator::Builder
|
|
70
74
|
# @return [void]
|
71
75
|
#
|
72
76
|
# @api private
|
73
|
-
# @since 0.
|
77
|
+
# @since 0.20.0
|
74
78
|
def initialize(
|
79
|
+
data_set_klass,
|
75
80
|
setting_key_pattern,
|
76
81
|
predefined_validator_name,
|
77
82
|
runtime_validation_method,
|
78
83
|
strict,
|
79
84
|
validation_logic
|
80
85
|
)
|
86
|
+
@data_set_klass = data_set_klass
|
81
87
|
@setting_key_pattern = setting_key_pattern
|
82
88
|
@predefined_validator_name = predefined_validator_name
|
83
89
|
@runtime_validation_method = runtime_validation_method
|
@@ -85,10 +91,12 @@ class Qonfig::Validator::Builder
|
|
85
91
|
@validation_logic = validation_logic
|
86
92
|
end
|
87
93
|
|
88
|
-
# @return [Qonfig::
|
94
|
+
# @return [Qonfig::Validation::Validators::MethodBased]
|
95
|
+
# @return [Qonfig::Validation::Validators::ProcBased]
|
96
|
+
# @return [Qonfig::Validation::Validators::Predefined]
|
89
97
|
#
|
90
98
|
# @api private
|
91
|
-
# @since 0.
|
99
|
+
# @since 0.20.0
|
92
100
|
def build
|
93
101
|
validate_attributes!
|
94
102
|
build_validator
|
@@ -96,22 +104,28 @@ class Qonfig::Validator::Builder
|
|
96
104
|
|
97
105
|
private
|
98
106
|
|
107
|
+
# @return [Class<Qonfig::DataSet>]
|
108
|
+
#
|
109
|
+
# @api private
|
110
|
+
# @since 0.20.0
|
111
|
+
attr_reader :data_set_klass
|
112
|
+
|
99
113
|
# @return [String, Symbol, NilClass]
|
100
114
|
#
|
101
115
|
# @api private
|
102
|
-
# @since 0.
|
116
|
+
# @since 0.20.0
|
103
117
|
attr_reader :setting_key_pattern
|
104
118
|
|
105
119
|
# @return [String, Symbol, NilClass]
|
106
120
|
#
|
107
121
|
# @api private
|
108
|
-
# @since 0.
|
122
|
+
# @since 0.20.0
|
109
123
|
attr_reader :predefined_validator_name
|
110
124
|
|
111
125
|
# @return [String, Symbol, NilClass]
|
112
126
|
#
|
113
127
|
# @api private
|
114
|
-
# @since 0.
|
128
|
+
# @since 0.20.0
|
115
129
|
attr_reader :runtime_validation_method
|
116
130
|
|
117
131
|
# @return [Boolean]
|
@@ -123,7 +137,7 @@ class Qonfig::Validator::Builder
|
|
123
137
|
# @return [Proc, NilClass]
|
124
138
|
#
|
125
139
|
# @api private
|
126
|
-
# @since 0.
|
140
|
+
# @since 0.20.0
|
127
141
|
attr_reader :validation_logic
|
128
142
|
|
129
143
|
# @return [void]
|
@@ -131,9 +145,9 @@ class Qonfig::Validator::Builder
|
|
131
145
|
# @raise [Qonfig::ArgumentError]
|
132
146
|
#
|
133
147
|
# @api private
|
134
|
-
# @since 0.
|
148
|
+
# @since 0.20.0
|
135
149
|
def validate_attributes!
|
136
|
-
|
150
|
+
AttributesConsistency.check!(
|
137
151
|
setting_key_pattern,
|
138
152
|
predefined_validator_name,
|
139
153
|
runtime_validation_method,
|
@@ -142,10 +156,12 @@ class Qonfig::Validator::Builder
|
|
142
156
|
)
|
143
157
|
end
|
144
158
|
|
145
|
-
# @return [Qonfig::
|
159
|
+
# @return [Qonfig::Validation::Validators::MethodBased]
|
160
|
+
# @return [Qonfig::Validation::Validators::ProcBased]
|
161
|
+
# @return [Qonfig::Validation::Validators::Predefined]
|
146
162
|
#
|
147
163
|
# @api private
|
148
|
-
# @since 0.
|
164
|
+
# @since 0.20.0
|
149
165
|
def build_validator
|
150
166
|
case
|
151
167
|
when predefined_validator_name then build_predefined_validator
|
@@ -157,38 +173,47 @@ class Qonfig::Validator::Builder
|
|
157
173
|
# @return [Qonfig::Settings::KeyMatcher, NilClass]
|
158
174
|
#
|
159
175
|
# @api private
|
160
|
-
# @since 0.
|
176
|
+
# @since 0.20.0
|
161
177
|
def build_setting_key_matcher
|
162
178
|
Qonfig::Settings::KeyMatcher.new(setting_key_pattern.to_s) if setting_key_pattern
|
163
179
|
end
|
164
180
|
|
165
|
-
# @return [Qonfig::
|
181
|
+
# @return [Qonfig::Validation::Validators::MethodBased]
|
166
182
|
#
|
167
183
|
# @api private
|
168
|
-
# @since 0.
|
184
|
+
# @since 0.20.0
|
169
185
|
def build_method_based_validator
|
170
|
-
Qonfig::
|
186
|
+
Qonfig::Validation::Validators::MethodBased.new(
|
171
187
|
build_setting_key_matcher, strict, runtime_validation_method
|
172
188
|
)
|
173
189
|
end
|
174
190
|
|
175
|
-
# @return [Qonfig::
|
191
|
+
# @return [Qonfig::Validation::Validators::ProcBased]
|
176
192
|
#
|
177
193
|
# @api private
|
178
|
-
# @since 0.
|
194
|
+
# @since 0.20.0
|
179
195
|
def build_proc_based_validator
|
180
|
-
Qonfig::
|
196
|
+
Qonfig::Validation::Validators::ProcBased.new(
|
181
197
|
build_setting_key_matcher, strict, validation_logic
|
182
198
|
)
|
183
199
|
end
|
184
200
|
|
185
|
-
# @return [Qonfig::
|
201
|
+
# @return [Qonfig::Validation::Validators::Predefined]
|
202
|
+
#
|
203
|
+
# @see Qonfig::Validation::Collections::PredefinedRegistry
|
186
204
|
#
|
187
205
|
# @api private
|
188
|
-
# @since 0.
|
206
|
+
# @since 0.20.0
|
189
207
|
def build_predefined_validator
|
190
|
-
|
191
|
-
|
208
|
+
predefined_validation_logic =
|
209
|
+
begin
|
210
|
+
data_set_klass.predefined_validators.resolve(predefined_validator_name)
|
211
|
+
rescue Qonfig::ValidatorNotFoundError
|
212
|
+
Qonfig::DataSet.predefined_validators.resolve(predefined_validator_name)
|
213
|
+
end
|
214
|
+
|
215
|
+
Qonfig::Validation::Validators::Predefined.new(
|
216
|
+
build_setting_key_matcher, strict, predefined_validation_logic
|
192
217
|
)
|
193
218
|
end
|
194
219
|
end
|