qonfig 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +457 -137
  4. data/lib/qonfig/command_set.rb +7 -1
  5. data/lib/qonfig/commands/add_nested_option.rb +3 -1
  6. data/lib/qonfig/commands/add_option.rb +2 -1
  7. data/lib/qonfig/commands/base.rb +2 -1
  8. data/lib/qonfig/commands/compose.rb +16 -10
  9. data/lib/qonfig/commands/expose_yaml.rb +2 -1
  10. data/lib/qonfig/commands/load_from_env.rb +2 -1
  11. data/lib/qonfig/commands/load_from_json.rb +2 -1
  12. data/lib/qonfig/commands/load_from_self.rb +2 -1
  13. data/lib/qonfig/commands/load_from_yaml.rb +2 -1
  14. data/lib/qonfig/data_set/lock.rb +46 -0
  15. data/lib/qonfig/data_set.rb +92 -23
  16. data/lib/qonfig/errors.rb +8 -0
  17. data/lib/qonfig/plugins/toml/commands/expose_toml.rb +2 -1
  18. data/lib/qonfig/plugins/toml/commands/load_from_toml.rb +2 -1
  19. data/lib/qonfig/settings/builder.rb +20 -4
  20. data/lib/qonfig/settings/callbacks.rb +43 -0
  21. data/lib/qonfig/settings/key_matcher.rb +175 -0
  22. data/lib/qonfig/settings/lock.rb +3 -3
  23. data/lib/qonfig/settings.rb +144 -33
  24. data/lib/qonfig/validator/basic.rb +53 -0
  25. data/lib/qonfig/validator/builder/attribute_consistency.rb +181 -0
  26. data/lib/qonfig/validator/builder.rb +169 -0
  27. data/lib/qonfig/validator/collection.rb +73 -0
  28. data/lib/qonfig/validator/dsl.rb +51 -0
  29. data/lib/qonfig/validator/method_based.rb +49 -0
  30. data/lib/qonfig/validator/predefined/common.rb +53 -0
  31. data/lib/qonfig/validator/predefined/registry.rb +83 -0
  32. data/lib/qonfig/validator/predefined/registry_control_mixin.rb +43 -0
  33. data/lib/qonfig/validator/predefined.rb +41 -0
  34. data/lib/qonfig/validator/proc_based.rb +53 -0
  35. data/lib/qonfig/validator.rb +58 -0
  36. data/lib/qonfig/version.rb +1 -1
  37. data/lib/qonfig.rb +1 -0
  38. data/qonfig.gemspec +1 -1
  39. metadata +19 -5
  40. data/lib/qonfig/data_set/validator.rb +0 -7
@@ -0,0 +1,41 @@
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
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.13.0
5
+ class Qonfig::Validator::ProcBased < Qonfig::Validator::Basic
6
+ # @return [Proc]
7
+ #
8
+ # @api private
9
+ # @since 0.13.0
10
+ attr_reader :validation
11
+
12
+ # @param setting_key_matcher [Qonfig::Settings::KeyMatcher, NilClass]
13
+ # @param vaidation [Proc]
14
+ # @return [void]
15
+ #
16
+ # @api private
17
+ # @since 0.13.0
18
+ def initialize(setting_key_matcher, validation)
19
+ super(setting_key_matcher)
20
+ @validation = validation
21
+ end
22
+
23
+ # @param data_set [Qonfig::DataSet]
24
+ # @return [Boolean]
25
+ #
26
+ # @raise [Qonfig::ValidationError]
27
+ #
28
+ # @api private
29
+ # @since 0.13.0
30
+ def validate_concrete(data_set)
31
+ data_set.settings.__deep_each_setting__ do |setting_key, setting_value|
32
+ next unless setting_key_matcher.match?(setting_key)
33
+
34
+ raise(
35
+ Qonfig::ValidationError,
36
+ "Invalid value of setting <#{setting_key}> (#{setting_value})"
37
+ ) unless data_set.instance_exec(setting_value, &validation)
38
+ end
39
+ end
40
+
41
+ # @param data_set [Qonfig::DataSet]
42
+ # @return [Boolean]
43
+ #
44
+ # @raise [Qonfig::ValidationError]
45
+ #
46
+ # @api private
47
+ # @since 0.13.0
48
+ def validate_full(data_set)
49
+ unless data_set.instance_eval(&validation)
50
+ raise(Qonfig::ValidationError, 'Invalid config object')
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.13.0
5
+ class Qonfig::Validator
6
+ require_relative 'validator/basic'
7
+ require_relative 'validator/method_based'
8
+ require_relative 'validator/proc_based'
9
+ require_relative 'validator/builder'
10
+ require_relative 'validator/collection'
11
+ require_relative 'validator/predefined'
12
+ require_relative 'validator/dsl'
13
+
14
+ # @param data_set [Qonfig::DataSet]
15
+ # @return [void]
16
+ #
17
+ # @api private
18
+ # @since 0.13.0
19
+ def initialize(data_set)
20
+ @data_set = data_set
21
+ @validators = data_set.class.validators.dup
22
+ end
23
+
24
+ # @return [void]
25
+ #
26
+ # @api private
27
+ # @since 0.13.0
28
+ def validate!
29
+ validators.each do |validator|
30
+ validator.validate(data_set)
31
+ end
32
+ end
33
+
34
+ # @return [Boolean]
35
+ #
36
+ # @api private
37
+ # @since 0.13.0
38
+ def valid?
39
+ validate!
40
+ true
41
+ rescue Qonfig::ValidationError
42
+ false
43
+ end
44
+
45
+ private
46
+
47
+ # @return [Qonfig::DataSet]
48
+ #
49
+ # @api private
50
+ # @since 0.13.0
51
+ attr_reader :data_set
52
+
53
+ # @return [Qonfig::Validator::Collection]
54
+ #
55
+ # @api private
56
+ # @since 0.13.0
57
+ attr_reader :validators
58
+ end
@@ -5,5 +5,5 @@ module Qonfig
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.12.0'
8
+ VERSION = '0.13.0'
9
9
  end
data/lib/qonfig.rb CHANGED
@@ -10,6 +10,7 @@ module Qonfig
10
10
  require_relative 'qonfig/uploaders'
11
11
  require_relative 'qonfig/commands'
12
12
  require_relative 'qonfig/command_set'
13
+ require_relative 'qonfig/validator'
13
14
  require_relative 'qonfig/settings'
14
15
  require_relative 'qonfig/dsl'
15
16
  require_relative 'qonfig/data_set'
data/qonfig.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'coveralls', '~> 0.8'
32
32
  spec.add_development_dependency 'simplecov', '~> 0.16'
33
33
  spec.add_development_dependency 'rspec', '~> 3.8'
34
- spec.add_development_dependency 'armitage-rubocop', '~> 0.73'
34
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.74'
35
35
 
36
36
  spec.add_development_dependency 'bundler'
37
37
  spec.add_development_dependency 'rake'
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.12.0
4
+ version: 0.13.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-07-19 00:00:00.000000000 Z
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.73'
61
+ version: '0.74'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.73'
68
+ version: '0.74'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +149,7 @@ files:
149
149
  - lib/qonfig/configurable.rb
150
150
  - lib/qonfig/data_set.rb
151
151
  - lib/qonfig/data_set/class_builder.rb
152
- - lib/qonfig/data_set/validator.rb
152
+ - lib/qonfig/data_set/lock.rb
153
153
  - lib/qonfig/dsl.rb
154
154
  - lib/qonfig/errors.rb
155
155
  - lib/qonfig/loaders.rb
@@ -170,13 +170,27 @@ files:
170
170
  - lib/qonfig/plugins/toml/uploaders/toml.rb
171
171
  - lib/qonfig/settings.rb
172
172
  - lib/qonfig/settings/builder.rb
173
+ - lib/qonfig/settings/callbacks.rb
173
174
  - lib/qonfig/settings/key_guard.rb
175
+ - lib/qonfig/settings/key_matcher.rb
174
176
  - lib/qonfig/settings/lock.rb
175
177
  - lib/qonfig/uploaders.rb
176
178
  - lib/qonfig/uploaders/base.rb
177
179
  - lib/qonfig/uploaders/file.rb
178
180
  - lib/qonfig/uploaders/json.rb
179
181
  - lib/qonfig/uploaders/yaml.rb
182
+ - lib/qonfig/validator.rb
183
+ - lib/qonfig/validator/basic.rb
184
+ - lib/qonfig/validator/builder.rb
185
+ - lib/qonfig/validator/builder/attribute_consistency.rb
186
+ - lib/qonfig/validator/collection.rb
187
+ - lib/qonfig/validator/dsl.rb
188
+ - lib/qonfig/validator/method_based.rb
189
+ - lib/qonfig/validator/predefined.rb
190
+ - lib/qonfig/validator/predefined/common.rb
191
+ - lib/qonfig/validator/predefined/registry.rb
192
+ - lib/qonfig/validator/predefined/registry_control_mixin.rb
193
+ - lib/qonfig/validator/proc_based.rb
180
194
  - lib/qonfig/version.rb
181
195
  - qonfig.gemspec
182
196
  homepage: https://github.com/0exp/qonfig
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api public
4
- # @since 0.?.0
5
- class Qonfig::DataSet::Validator
6
- # TODO: think about validation layer
7
- end