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
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.20.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-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -58,20 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 0.76.0.3
|
61
|
+
version: '0.77'
|
65
62
|
type: :development
|
66
63
|
prerelease: false
|
67
64
|
version_requirements: !ruby/object:Gem::Requirement
|
68
65
|
requirements:
|
69
66
|
- - "~>"
|
70
67
|
- !ruby/object:Gem::Version
|
71
|
-
version: '0.
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.76.0.3
|
68
|
+
version: '0.77'
|
75
69
|
- !ruby/object:Gem::Dependency
|
76
70
|
name: bundler
|
77
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,6 +150,7 @@ files:
|
|
156
150
|
- lib/qonfig/commands/definition/load_from_json.rb
|
157
151
|
- lib/qonfig/commands/definition/load_from_self.rb
|
158
152
|
- lib/qonfig/commands/definition/load_from_yaml.rb
|
153
|
+
- lib/qonfig/commands/definition/re_define_option.rb
|
159
154
|
- lib/qonfig/commands/instantiation.rb
|
160
155
|
- lib/qonfig/commands/instantiation/freeze_state.rb
|
161
156
|
- lib/qonfig/commands/instantiation/values_file.rb
|
@@ -186,8 +181,8 @@ files:
|
|
186
181
|
- lib/qonfig/plugins/pretty_print/mixin.rb
|
187
182
|
- lib/qonfig/plugins/registry.rb
|
188
183
|
- lib/qonfig/plugins/toml.rb
|
189
|
-
- lib/qonfig/plugins/toml/commands/expose_toml.rb
|
190
|
-
- lib/qonfig/plugins/toml/commands/load_from_toml.rb
|
184
|
+
- lib/qonfig/plugins/toml/commands/definition/expose_toml.rb
|
185
|
+
- lib/qonfig/plugins/toml/commands/definition/load_from_toml.rb
|
191
186
|
- lib/qonfig/plugins/toml/data_set.rb
|
192
187
|
- lib/qonfig/plugins/toml/dsl.rb
|
193
188
|
- lib/qonfig/plugins/toml/errors.rb
|
@@ -207,18 +202,21 @@ files:
|
|
207
202
|
- lib/qonfig/uploaders/file.rb
|
208
203
|
- lib/qonfig/uploaders/json.rb
|
209
204
|
- lib/qonfig/uploaders/yaml.rb
|
210
|
-
- lib/qonfig/
|
211
|
-
- lib/qonfig/
|
212
|
-
- lib/qonfig/
|
213
|
-
- lib/qonfig/
|
214
|
-
- lib/qonfig/
|
215
|
-
- lib/qonfig/
|
216
|
-
- lib/qonfig/
|
217
|
-
- lib/qonfig/
|
218
|
-
- lib/qonfig/
|
219
|
-
- lib/qonfig/
|
220
|
-
- lib/qonfig/
|
221
|
-
- lib/qonfig/
|
205
|
+
- lib/qonfig/validation.rb
|
206
|
+
- lib/qonfig/validation/building.rb
|
207
|
+
- lib/qonfig/validation/building/instance_builder.rb
|
208
|
+
- lib/qonfig/validation/building/instance_builder/attribute_consistency.rb
|
209
|
+
- lib/qonfig/validation/building/predefined_builder.rb
|
210
|
+
- lib/qonfig/validation/collections.rb
|
211
|
+
- lib/qonfig/validation/collections/instance_collection.rb
|
212
|
+
- lib/qonfig/validation/collections/predefined_registry.rb
|
213
|
+
- lib/qonfig/validation/predefinition_mixin.rb
|
214
|
+
- lib/qonfig/validation/validators.rb
|
215
|
+
- lib/qonfig/validation/validators/basic.rb
|
216
|
+
- lib/qonfig/validation/validators/composite.rb
|
217
|
+
- lib/qonfig/validation/validators/method_based.rb
|
218
|
+
- lib/qonfig/validation/validators/predefined.rb
|
219
|
+
- lib/qonfig/validation/validators/proc_based.rb
|
222
220
|
- lib/qonfig/version.rb
|
223
221
|
- qonfig.gemspec
|
224
222
|
homepage: https://github.com/0exp/qonfig
|
@@ -240,8 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
238
|
- !ruby/object:Gem::Version
|
241
239
|
version: '0'
|
242
240
|
requirements: []
|
243
|
-
|
244
|
-
rubygems_version: 2.7.6
|
241
|
+
rubygems_version: 3.0.3
|
245
242
|
signing_key:
|
246
243
|
specification_version: 4
|
247
244
|
summary: Config object
|
data/lib/qonfig/validator/dsl.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.13.0
|
5
|
-
module Qonfig::Validator::DSL
|
6
|
-
class << self
|
7
|
-
# @param child_klass [Qonfig::DataSet]
|
8
|
-
# @return [void]
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
# @since 0.13.0
|
12
|
-
def extended(child_klass)
|
13
|
-
child_klass.instance_variable_set(:@validators, Qonfig::Validator::Collection.new)
|
14
|
-
|
15
|
-
child_klass.singleton_class.prepend(Module.new do
|
16
|
-
def inherited(child_klass)
|
17
|
-
child_klass.instance_variable_set(:@validators, Qonfig::Validator::Collection.new)
|
18
|
-
child_klass.validators.concat(validators)
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return [Qonfig::Validator::Collection]
|
26
|
-
#
|
27
|
-
# @api private
|
28
|
-
# @since 0.13.0
|
29
|
-
def validators
|
30
|
-
@validators
|
31
|
-
end
|
32
|
-
|
33
|
-
# @param setting_key_pattern [String, Symbol, NilClass]
|
34
|
-
# @param predefined [String, Symbol]
|
35
|
-
# @option by [String, Symbol, NilClass]
|
36
|
-
# @option stict [Boolean]
|
37
|
-
# @param custom_validation [Proc]
|
38
|
-
# @return [void]
|
39
|
-
#
|
40
|
-
# @see Qonfig::Validator::Builder
|
41
|
-
#
|
42
|
-
# @api private
|
43
|
-
# @since 0.13.0
|
44
|
-
def validate(
|
45
|
-
setting_key_pattern = nil,
|
46
|
-
predefined = nil,
|
47
|
-
strict: false,
|
48
|
-
by: nil,
|
49
|
-
&custom_validation
|
50
|
-
)
|
51
|
-
validators << Qonfig::Validator::Builder.build(
|
52
|
-
setting_key_pattern: setting_key_pattern,
|
53
|
-
predefined_validator: predefined,
|
54
|
-
runtime_validation_method: by,
|
55
|
-
strict: strict,
|
56
|
-
validation_logic: custom_validation
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.13.0
|
5
|
-
class Qonfig::Validator::Predefined::Registry
|
6
|
-
# @return [void]
|
7
|
-
#
|
8
|
-
# @api private
|
9
|
-
# @since 0.13.0
|
10
|
-
def initialize
|
11
|
-
@validators = {}
|
12
|
-
@lock = Mutex.new
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param name [String, Symbol]
|
16
|
-
# @param validation [Proc]
|
17
|
-
# @return [void]
|
18
|
-
#
|
19
|
-
# @raise [Qonfig::ValidatorArgumentError]
|
20
|
-
#
|
21
|
-
# @api private
|
22
|
-
# @since 0.13.0
|
23
|
-
def register(name, &validation)
|
24
|
-
thread_safe do
|
25
|
-
name = indifferently_accessable_name(name)
|
26
|
-
|
27
|
-
raise(
|
28
|
-
Qonfig::ValidatorArgumentError,
|
29
|
-
"Predefined validator with name '#{name}' already exists."
|
30
|
-
) if validators.key?(name)
|
31
|
-
|
32
|
-
validators[name] = validation
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# @param name [String, Symbol]
|
37
|
-
# @return [Qonfig::Validator::ProcBased, Qonfig::Validator::MethodBased]
|
38
|
-
#
|
39
|
-
# @raise [Qonfig::ValidatorArgumentError]
|
40
|
-
#
|
41
|
-
# @api private
|
42
|
-
# @since 0.13.0
|
43
|
-
def resolve(name)
|
44
|
-
thread_safe do
|
45
|
-
begin
|
46
|
-
validators.fetch(indifferently_accessable_name(name))
|
47
|
-
rescue KeyError
|
48
|
-
raise(
|
49
|
-
Qonfig::ValidatorArgumentError,
|
50
|
-
"Predefined validator with name '#{name}' does not exist."
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
# @return [Hash<String,Proc>]
|
59
|
-
#
|
60
|
-
# @api private
|
61
|
-
# @since 0.13.0
|
62
|
-
attr_reader :validators
|
63
|
-
|
64
|
-
# @param name [String, Symbol]
|
65
|
-
# @return [String]
|
66
|
-
#
|
67
|
-
# @api private
|
68
|
-
# @since 0.13.0
|
69
|
-
def indifferently_accessable_name(name)
|
70
|
-
name.to_s
|
71
|
-
end
|
72
|
-
|
73
|
-
# @param block [Proc]
|
74
|
-
# @return [Any]
|
75
|
-
#
|
76
|
-
# @api private
|
77
|
-
# @since 0.13.0
|
78
|
-
def thread_safe(&block)
|
79
|
-
@lock.synchronize(&block)
|
80
|
-
end
|
81
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.13.0
|
5
|
-
module Qonfig::Validator::Predefined::RegistryControlMixin
|
6
|
-
class << self
|
7
|
-
# @param basic_klass [Class, Module]
|
8
|
-
# @return [void]
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
# @since 0.13.0
|
12
|
-
def extended(basic_klass)
|
13
|
-
basic_klass.instance_variable_set(:@registry, Qonfig::Validator::Predefined::Registry.new)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [Qonfig::Validator::Predefined::Registry]
|
18
|
-
#
|
19
|
-
# @api private
|
20
|
-
# @since 0.13.0
|
21
|
-
attr_reader :registry
|
22
|
-
|
23
|
-
# @param name [String, Symbol]
|
24
|
-
# @param validation [Proc]
|
25
|
-
# @return [void]
|
26
|
-
#
|
27
|
-
# @api private
|
28
|
-
# @since 0.13.0
|
29
|
-
def predefine(name, &validation)
|
30
|
-
registry.register(name, &validation)
|
31
|
-
end
|
32
|
-
|
33
|
-
# @param name [String, Symbol]
|
34
|
-
# @param setting_key_matcher [Qonfig::Setting::KeyMatcher]
|
35
|
-
# @param strict [Boolean]
|
36
|
-
# @return [Qonfig::Validator::Predefined::Common]
|
37
|
-
#
|
38
|
-
# @api private
|
39
|
-
# @since 0.13.0
|
40
|
-
def build(name, setting_key_matcher, strict)
|
41
|
-
validation = registry.resolve(name)
|
42
|
-
Qonfig::Validator::Predefined::Common.new(setting_key_matcher, strict, validation)
|
43
|
-
end
|
44
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.13.0
|
5
|
-
module Qonfig::Validator::Predefined
|
6
|
-
require_relative 'predefined/common'
|
7
|
-
require_relative 'predefined/registry'
|
8
|
-
require_relative 'predefined/registry_control_mixin'
|
9
|
-
|
10
|
-
# @since 0.13.0
|
11
|
-
extend Qonfig::Validator::Predefined::RegistryControlMixin
|
12
|
-
|
13
|
-
# @since 0.13.0
|
14
|
-
predefine(:integer) { |value| value.is_a?(Integer) }
|
15
|
-
# @since 0.13.0
|
16
|
-
predefine(:float) { |value| value.is_a?(Float) }
|
17
|
-
# @since 0.13.0
|
18
|
-
predefine(:numeric) { |value| value.is_a?(Numeric) }
|
19
|
-
# @since 0.13.0
|
20
|
-
predefine(:string) { |value| value.is_a?(String) }
|
21
|
-
# @since 0.13.0
|
22
|
-
predefine(:symbol) { |value| value.is_a?(Symbol) }
|
23
|
-
# @since 0.13.0
|
24
|
-
predefine(:text) { |value| value.is_a?(Symbol) || value.is_a?(String) }
|
25
|
-
# @since 0.13.0
|
26
|
-
predefine(:array) { |value| value.is_a?(Array) }
|
27
|
-
# @since 0.13.0
|
28
|
-
predefine(:hash) { |value| value.is_a?(Hash) }
|
29
|
-
# @since 0.13.0
|
30
|
-
predefine(:big_decimal) { |value| value.is_a?(BigDecimal) }
|
31
|
-
# @since 0.13.0
|
32
|
-
predefine(:boolean) { |value| value.is_a?(TrueClass) || value.is_a?(FalseClass) }
|
33
|
-
# @since 0.13.0
|
34
|
-
predefine(:proc) { |value| value.is_a?(Proc) }
|
35
|
-
# @since 0.13.0
|
36
|
-
predefine(:class) { |value| value.is_a?(Class) }
|
37
|
-
# @since 0.13.0
|
38
|
-
predefine(:module) { |value| value.is_a?(Module) }
|
39
|
-
# @since 0.13.0
|
40
|
-
predefine(:not_nil) { |value| !value.nil? }
|
41
|
-
end
|