smart_schema 0.12.0 → 0.12.1
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
- metadata +3 -83
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -20
- data/CHANGELOG.md +0 -79
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -266
- data/LICENSE.txt +0 -21
- data/README.md +0 -305
- data/Rakefile +0 -21
- data/bin/console +0 -8
- data/bin/setup +0 -8
- data/lib/smart_core/schema/checker/reconciler/constructor.rb +0 -60
- data/lib/smart_core/schema/checker/reconciler/matcher/options.rb +0 -33
- data/lib/smart_core/schema/checker/reconciler/matcher/result.rb +0 -87
- data/lib/smart_core/schema/checker/reconciler/matcher/result_finalizer.rb +0 -186
- data/lib/smart_core/schema/checker/reconciler/matcher.rb +0 -62
- data/lib/smart_core/schema/checker/reconciler.rb +0 -106
- data/lib/smart_core/schema/checker/rules/base.rb +0 -110
- data/lib/smart_core/schema/checker/rules/extra_keys/failure.rb +0 -24
- data/lib/smart_core/schema/checker/rules/extra_keys/result.rb +0 -37
- data/lib/smart_core/schema/checker/rules/extra_keys/success.rb +0 -30
- data/lib/smart_core/schema/checker/rules/extra_keys.rb +0 -31
- data/lib/smart_core/schema/checker/rules/optional.rb +0 -27
- data/lib/smart_core/schema/checker/rules/options/empty.rb +0 -43
- data/lib/smart_core/schema/checker/rules/options/filled.rb +0 -49
- data/lib/smart_core/schema/checker/rules/options/type.rb +0 -88
- data/lib/smart_core/schema/checker/rules/options.rb +0 -60
- data/lib/smart_core/schema/checker/rules/required.rb +0 -27
- data/lib/smart_core/schema/checker/rules/requirement/optional.rb +0 -36
- data/lib/smart_core/schema/checker/rules/requirement/required.rb +0 -36
- data/lib/smart_core/schema/checker/rules/requirement/result.rb +0 -95
- data/lib/smart_core/schema/checker/rules/requirement.rb +0 -9
- data/lib/smart_core/schema/checker/rules/result/base.rb +0 -44
- data/lib/smart_core/schema/checker/rules/result/failure.rb +0 -41
- data/lib/smart_core/schema/checker/rules/result/success.rb +0 -15
- data/lib/smart_core/schema/checker/rules/result.rb +0 -9
- data/lib/smart_core/schema/checker/rules/type_aliases.rb +0 -57
- data/lib/smart_core/schema/checker/rules/verifier/result.rb +0 -75
- data/lib/smart_core/schema/checker/rules/verifier.rb +0 -74
- data/lib/smart_core/schema/checker/rules.rb +0 -89
- data/lib/smart_core/schema/checker/verifiable_hash.rb +0 -65
- data/lib/smart_core/schema/checker.rb +0 -106
- data/lib/smart_core/schema/configuration.rb +0 -33
- data/lib/smart_core/schema/dsl.rb +0 -81
- data/lib/smart_core/schema/errors.rb +0 -65
- data/lib/smart_core/schema/key_control.rb +0 -39
- data/lib/smart_core/schema/plugins/abstract.rb +0 -55
- data/lib/smart_core/schema/plugins/access_mixin.rb +0 -47
- data/lib/smart_core/schema/plugins/dry_types/dry_types/abstract_factory.rb +0 -91
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/base.rb +0 -9
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/cast.rb +0 -21
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/valid.rb +0 -16
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/validate.rb +0 -19
- data/lib/smart_core/schema/plugins/dry_types/dry_types/operation.rb +0 -12
- data/lib/smart_core/schema/plugins/dry_types/dry_types.rb +0 -10
- data/lib/smart_core/schema/plugins/dry_types/errors.rb +0 -13
- data/lib/smart_core/schema/plugins/dry_types.rb +0 -27
- data/lib/smart_core/schema/plugins/registry.rb +0 -158
- data/lib/smart_core/schema/plugins/registry_interface.rb +0 -63
- data/lib/smart_core/schema/plugins.rb +0 -17
- data/lib/smart_core/schema/result.rb +0 -62
- data/lib/smart_core/schema/type_system/interop/abstract_factory.rb +0 -80
- data/lib/smart_core/schema/type_system/interop/aliasing/alias_list.rb +0 -131
- data/lib/smart_core/schema/type_system/interop/aliasing.rb +0 -72
- data/lib/smart_core/schema/type_system/interop/operation.rb +0 -30
- data/lib/smart_core/schema/type_system/interop.rb +0 -120
- data/lib/smart_core/schema/type_system/registry.rb +0 -162
- data/lib/smart_core/schema/type_system/registry_interface.rb +0 -87
- data/lib/smart_core/schema/type_system/smart_types/abstract_factory.rb +0 -91
- data/lib/smart_core/schema/type_system/smart_types/operation/base.rb +0 -8
- data/lib/smart_core/schema/type_system/smart_types/operation/cast.rb +0 -16
- data/lib/smart_core/schema/type_system/smart_types/operation/valid.rb +0 -16
- data/lib/smart_core/schema/type_system/smart_types/operation/validate.rb +0 -16
- data/lib/smart_core/schema/type_system/smart_types/operation.rb +0 -13
- data/lib/smart_core/schema/type_system/smart_types.rb +0 -48
- data/lib/smart_core/schema/type_system.rb +0 -16
- data/lib/smart_core/schema/version.rb +0 -14
- data/lib/smart_core/schema.rb +0 -67
- data/smart_schema.gemspec +0 -46
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# TODO: refactor error data propagating (with Value Object)
|
|
4
|
-
|
|
5
|
-
# @api private
|
|
6
|
-
# @since 0.1.0
|
|
7
|
-
# @version 0.3.0
|
|
8
|
-
module SmartCore::Schema::Checker::Reconciler::Matcher::ResultFinalizer
|
|
9
|
-
# @return [Proc]
|
|
10
|
-
#
|
|
11
|
-
# @api private
|
|
12
|
-
# @since 0.1.0
|
|
13
|
-
ERRORS_CONTAINER_BUILDER = -> { Hash.new { |hash, key| hash[key] = Set.new } }
|
|
14
|
-
|
|
15
|
-
# @return [Proc]
|
|
16
|
-
#
|
|
17
|
-
# @api private
|
|
18
|
-
# @since 0.1.0
|
|
19
|
-
EXTRA_KEYS_CONTAINER_BUILDER = -> { Set.new }
|
|
20
|
-
|
|
21
|
-
# @return [Proc]
|
|
22
|
-
#
|
|
23
|
-
# @api private
|
|
24
|
-
# @since 0.3.0
|
|
25
|
-
SPREAD_KEYS_CONTAINER_BUILDER = -> { Set.new }
|
|
26
|
-
|
|
27
|
-
# @return [Symbol]
|
|
28
|
-
#
|
|
29
|
-
# @api private
|
|
30
|
-
# @since 0.2.0
|
|
31
|
-
EXTRA_KEY_ERROR_CODE = :extra_key
|
|
32
|
-
|
|
33
|
-
class << self
|
|
34
|
-
# @param result [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
35
|
-
# @return [SmartCore::Schema::Result]
|
|
36
|
-
#
|
|
37
|
-
# @ai privates
|
|
38
|
-
# @since 0.1.0
|
|
39
|
-
# @version 0.3.0
|
|
40
|
-
# rubocop:disable Layout/LineLength
|
|
41
|
-
def finalize(result)
|
|
42
|
-
schema_errors, extra_keys, spread_keys = aggregate_errors(result)
|
|
43
|
-
schema_errors, extra_keys, spread_keys = compile_errors(schema_errors, extra_keys, spread_keys)
|
|
44
|
-
build_final_result(result, schema_errors, extra_keys, spread_keys)
|
|
45
|
-
end
|
|
46
|
-
# rubocop:enable Layout/LineLength
|
|
47
|
-
|
|
48
|
-
private
|
|
49
|
-
|
|
50
|
-
# @param result [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
51
|
-
# @param schema_errors [Hash<String,Array<Symbol>>]
|
|
52
|
-
# @param extra_keys [Set<String>]
|
|
53
|
-
# @param spread_keys [Set<String>]
|
|
54
|
-
# @return [SmartCore::Schema::Result]
|
|
55
|
-
#
|
|
56
|
-
# @api private
|
|
57
|
-
# @since 0.1.0
|
|
58
|
-
# @version 0.3.0
|
|
59
|
-
def build_final_result(result, schema_errors, extra_keys, spread_keys)
|
|
60
|
-
SmartCore::Schema::Result.new(
|
|
61
|
-
result.verifiable_hash.source,
|
|
62
|
-
schema_errors.freeze,
|
|
63
|
-
extra_keys.freeze,
|
|
64
|
-
SPREAD_KEYS_CONTAINER_BUILDER.call.freeze # TODO: spread_keys.freeze
|
|
65
|
-
)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# @param result [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
69
|
-
# @return [Array<Hash<String,Any>,Set<String>>]
|
|
70
|
-
#
|
|
71
|
-
# @api private
|
|
72
|
-
# @since 0.1.0
|
|
73
|
-
def aggregate_errors(result)
|
|
74
|
-
schema_errors = ERRORS_CONTAINER_BUILDER.call
|
|
75
|
-
extra_keys = EXTRA_KEYS_CONTAINER_BUILDER.call
|
|
76
|
-
spread_keys = SPREAD_KEYS_CONTAINER_BUILDER.call
|
|
77
|
-
|
|
78
|
-
result.each_result do |concrete_result|
|
|
79
|
-
case concrete_result
|
|
80
|
-
when SmartCore::Schema::Checker::Rules::Verifier::Result
|
|
81
|
-
aggregate_verifier_errors(concrete_result, schema_errors)
|
|
82
|
-
when SmartCore::Schema::Checker::Rules::ExtraKeys::Failure
|
|
83
|
-
aggregate_extra_keys_errors(concrete_result, extra_keys)
|
|
84
|
-
when SmartCore::Schema::Checker::Rules::ExtraKeys::Success
|
|
85
|
-
aggregate_spread_keys_notice(concrete_result, spread_keys)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
[schema_errors, extra_keys, spread_keys]
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# @param result [SmartCore::Schema::Checker::Rules::Verifier::Result]
|
|
93
|
-
# @param errors [Hash<String,Array<String>|Hash<String,Hash>>]
|
|
94
|
-
# @return [void]
|
|
95
|
-
#
|
|
96
|
-
# @api private
|
|
97
|
-
# @since 0.1.0
|
|
98
|
-
def aggregate_verifier_errors(result, errors)
|
|
99
|
-
result.each_result do |concrete_result|
|
|
100
|
-
case concrete_result
|
|
101
|
-
when SmartCore::Schema::Checker::Reconciler::Matcher::Result
|
|
102
|
-
sub_schema_errors, sub_extra_keys = aggregate_errors(concrete_result)
|
|
103
|
-
errors[result.key] << [sub_schema_errors, sub_extra_keys]
|
|
104
|
-
when SmartCore::Schema::Checker::Rules::Requirement::Result
|
|
105
|
-
errors[concrete_result.key] << concrete_result.error if concrete_result.failure?
|
|
106
|
-
when SmartCore::Schema::Checker::Rules::Result::Failure
|
|
107
|
-
errors[concrete_result.key] << concrete_result.error
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
# @param result [SmartCore::Schema::Checker::Rules::ExtraKeys::Failure]
|
|
113
|
-
# @param extra_keys [Set<String>]
|
|
114
|
-
# @return [void]
|
|
115
|
-
#
|
|
116
|
-
# @api private
|
|
117
|
-
# @since 0.1.0
|
|
118
|
-
def aggregate_extra_keys_errors(result, extra_keys)
|
|
119
|
-
extra_keys.merge(result.extra_keys)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# @param result [SmartCore::Schema::Checker::Rules::ExtraKeys::Success]
|
|
123
|
-
# @param spread_keys [Set<String>]
|
|
124
|
-
# @return [void]
|
|
125
|
-
#
|
|
126
|
-
# @api private
|
|
127
|
-
# @since 0.3.0
|
|
128
|
-
def aggregate_spread_keys_notice(result, spread_keys)
|
|
129
|
-
spread_keys.merge(result.spread_keys)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# @param errors [Hash]
|
|
133
|
-
# @param extra_keys [Set]
|
|
134
|
-
# @param spread_keys [Set]
|
|
135
|
-
# @param initial_error_key [NilClass, String]
|
|
136
|
-
# @return [Array<Hash<String,Set<Symbol>>,Set<String>]
|
|
137
|
-
#
|
|
138
|
-
# @api private
|
|
139
|
-
# @since 0.1.0
|
|
140
|
-
# @version 0.3.0
|
|
141
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
142
|
-
def compile_errors(errors, extra_keys, spread_keys, initial_error_key = nil)
|
|
143
|
-
compiled_errors = ERRORS_CONTAINER_BUILDER.call
|
|
144
|
-
compiled_extra_keys = EXTRA_KEYS_CONTAINER_BUILDER.call
|
|
145
|
-
compiled_spread_keys = SPREAD_KEYS_CONTAINER_BUILDER.call
|
|
146
|
-
|
|
147
|
-
compiled_extra_keys.merge(extra_keys).map! do |key|
|
|
148
|
-
# dot-notated nested keys
|
|
149
|
-
initial_error_key ? "#{initial_error_key}.#{key}" : key
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
compiled_spread_keys.merge(spread_keys).map! do |key|
|
|
153
|
-
# dot-notated nested keys
|
|
154
|
-
initial_error_key ? "#{initial_error_key}.#{key}" : key
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
errors.each_pair do |key, error_set|
|
|
158
|
-
# dot-notated nested key
|
|
159
|
-
compiled_key = initial_error_key ? "#{initial_error_key}.#{key}" : key
|
|
160
|
-
|
|
161
|
-
error_set.each do |error|
|
|
162
|
-
case error
|
|
163
|
-
when Symbol # error code
|
|
164
|
-
compiled_errors[compiled_key] << error
|
|
165
|
-
when Array # nested errors
|
|
166
|
-
sub_errors, sub_extra_keys = error
|
|
167
|
-
sub_spread_keys = SPREAD_KEYS_CONTAINER_BUILDER.call
|
|
168
|
-
compiled_sub_errors, compiled_sub_extra_keys, compiled_sub_spread_keys = compile_errors(
|
|
169
|
-
sub_errors, sub_extra_keys, sub_spread_keys, compiled_key
|
|
170
|
-
)
|
|
171
|
-
compiled_errors.merge!(compiled_sub_errors)
|
|
172
|
-
compiled_extra_keys.merge(compiled_sub_extra_keys)
|
|
173
|
-
compiled_spread_keys.merge(compiled_sub_spread_keys)
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
compiled_extra_keys.each do |compiled_extra_key|
|
|
179
|
-
compiled_errors[compiled_extra_key] << EXTRA_KEY_ERROR_CODE
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
[compiled_errors, compiled_extra_keys, compiled_spread_keys]
|
|
183
|
-
end
|
|
184
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
185
|
-
end
|
|
186
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
# @version 0.3.0
|
|
6
|
-
module SmartCore::Schema::Checker::Reconciler::Matcher
|
|
7
|
-
require_relative 'matcher/options'
|
|
8
|
-
require_relative 'matcher/result'
|
|
9
|
-
require_relative 'matcher/result_finalizer'
|
|
10
|
-
|
|
11
|
-
class << self
|
|
12
|
-
# @param reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
13
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
14
|
-
# @return [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
15
|
-
#
|
|
16
|
-
# @api private
|
|
17
|
-
# @since 0.1.0
|
|
18
|
-
# @version 0.3.0
|
|
19
|
-
def match(reconciler, verifiable_hash)
|
|
20
|
-
matcher_options = Options.build_from(reconciler)
|
|
21
|
-
|
|
22
|
-
Result.new(verifiable_hash).tap do |result|
|
|
23
|
-
match_for_contract_keys(reconciler, matcher_options, verifiable_hash, result)
|
|
24
|
-
match_for_extra_keys(reconciler, matcher_options, verifiable_hash, result)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
# @param reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
31
|
-
# @param matcher_options [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
32
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
33
|
-
# @param result [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
34
|
-
# @return [void]
|
|
35
|
-
#
|
|
36
|
-
# @api private
|
|
37
|
-
# @since 0.1.0
|
|
38
|
-
# @version 0.3.0
|
|
39
|
-
def match_for_contract_keys(reconciler, matcher_options, verifiable_hash, result)
|
|
40
|
-
reconciler.__contract_rules.each_rule do |rule|
|
|
41
|
-
verification_result = rule.__verify!(verifiable_hash, matcher_options)
|
|
42
|
-
result.contract_key_result(verification_result)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# @param reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
47
|
-
# @param matcher_options [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
48
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
49
|
-
# @param result [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
50
|
-
# @return [void]
|
|
51
|
-
#
|
|
52
|
-
# @api private
|
|
53
|
-
# @since 0.1.0
|
|
54
|
-
# @version 0.3.0
|
|
55
|
-
def match_for_extra_keys(reconciler, matcher_options, verifiable_hash, result)
|
|
56
|
-
verification_result = reconciler.__extra_keys_contract.__verify!(
|
|
57
|
-
verifiable_hash, reconciler.__contract_rules, matcher_options
|
|
58
|
-
)
|
|
59
|
-
result.extra_keys_result(verification_result)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
# @version 0.8.0
|
|
6
|
-
class SmartCore::Schema::Checker::Reconciler
|
|
7
|
-
require_relative 'reconciler/constructor'
|
|
8
|
-
require_relative 'reconciler/matcher'
|
|
9
|
-
|
|
10
|
-
# @return [void]
|
|
11
|
-
#
|
|
12
|
-
# @api private
|
|
13
|
-
# @since 0.1.0
|
|
14
|
-
# @version 0.3.0
|
|
15
|
-
def initialize
|
|
16
|
-
@rules = SmartCore::Schema::Checker::Rules.new
|
|
17
|
-
@strict = Constructor::DEFAULT_STRICT_BEHAVIOR
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
21
|
-
# @return [void]
|
|
22
|
-
#
|
|
23
|
-
# @api private
|
|
24
|
-
# @since 0.1.0
|
|
25
|
-
# @version 0.8.0
|
|
26
|
-
def __match!(verifiable_hash)
|
|
27
|
-
SmartCore::Schema::Checker::Reconciler::Matcher.match(self, verifiable_hash)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# @return [SmartCore::Schema::Checker::Rules::ExtraKeys]
|
|
31
|
-
#
|
|
32
|
-
# @api private
|
|
33
|
-
# @since 0.1.0
|
|
34
|
-
def __extra_keys_contract
|
|
35
|
-
SmartCore::Schema::Checker::Rules::ExtraKeys
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# @return [SmartCore::Schema::Checker::Rules]
|
|
39
|
-
#
|
|
40
|
-
# @api private
|
|
41
|
-
# @since 0.1.0
|
|
42
|
-
# @version 0.8.0
|
|
43
|
-
def __contract_rules
|
|
44
|
-
rules
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# @return [Boolean]
|
|
48
|
-
#
|
|
49
|
-
# @api private
|
|
50
|
-
# @since 0.3.0
|
|
51
|
-
# @version 0.8.0
|
|
52
|
-
def __strict?
|
|
53
|
-
@strict
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# @param schema_key [String, Symbol]
|
|
57
|
-
# @param nested_definitions [Block]
|
|
58
|
-
# @return [SmartCore::Schema::Checker::Rules::Required]
|
|
59
|
-
#
|
|
60
|
-
# @api public
|
|
61
|
-
# @since 0.1.0
|
|
62
|
-
# @version 0.8.0
|
|
63
|
-
def required(schema_key, &nested_definitions)
|
|
64
|
-
rule = SmartCore::Schema::Checker::Rules::Required.new(self, schema_key, &nested_definitions)
|
|
65
|
-
rule.tap { rules[rule.schema_key] = rule }
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# @param schema_key [String, Symbol]
|
|
69
|
-
# @param nested_definitions [Block]
|
|
70
|
-
# @return [SmartCore::Schema::Checker::Rules::Optional]
|
|
71
|
-
#
|
|
72
|
-
# @api public
|
|
73
|
-
# @since 0.1.0
|
|
74
|
-
# @version 0.8.0
|
|
75
|
-
def optional(schema_key, &nested_definitions)
|
|
76
|
-
rule = SmartCore::Schema::Checker::Rules::Optional.new(self, schema_key, &nested_definitions)
|
|
77
|
-
rule.tap { rules[rule.schema_key] = rule }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# @param is_strict [Boolean]
|
|
81
|
-
# @return [void]
|
|
82
|
-
#
|
|
83
|
-
# @api public
|
|
84
|
-
# @since 0.3.0
|
|
85
|
-
# @version 0.8.0
|
|
86
|
-
def strict!(is_strict = Constructor::DEFAULT_STRICT_BEHAVIOR)
|
|
87
|
-
@strict = is_strict
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# @return [void]
|
|
91
|
-
#
|
|
92
|
-
# @api public
|
|
93
|
-
# @since 0.3.0
|
|
94
|
-
# @version 0.8.0
|
|
95
|
-
def non_strict!
|
|
96
|
-
strict!(Constructor::STRICT_MODES[:non_strict])
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
private
|
|
100
|
-
|
|
101
|
-
# @return [SmartCore::Schema::Checker::Rules]
|
|
102
|
-
#
|
|
103
|
-
# @api private
|
|
104
|
-
# @since 0.1.0
|
|
105
|
-
attr_reader :rules
|
|
106
|
-
end
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
# @version 0.8.0
|
|
6
|
-
class SmartCore::Schema::Checker::Rules::Base
|
|
7
|
-
# @return [String]
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
# @since 0.1.0
|
|
11
|
-
attr_reader :schema_key
|
|
12
|
-
|
|
13
|
-
# @return [SmartCore::Schema::Checker::Rules::Options]
|
|
14
|
-
#
|
|
15
|
-
# @api private
|
|
16
|
-
# @since 0.1.0
|
|
17
|
-
attr_reader :options
|
|
18
|
-
|
|
19
|
-
# @return [NilClass, SmartCore::Schema::Checker::Reconciler]
|
|
20
|
-
#
|
|
21
|
-
# @api private
|
|
22
|
-
# @since 0.1.0
|
|
23
|
-
attr_reader :nested_reconciler
|
|
24
|
-
|
|
25
|
-
# @return [SmartCore::Schema::Checker::Reconciler]
|
|
26
|
-
#
|
|
27
|
-
# @api private
|
|
28
|
-
# @since 0.3.0
|
|
29
|
-
attr_reader :root_reconciler
|
|
30
|
-
|
|
31
|
-
# @param root_reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
32
|
-
# @param schema_key [String, Symbol]
|
|
33
|
-
# @param nested_definitions [Block]
|
|
34
|
-
# @return [void]
|
|
35
|
-
#
|
|
36
|
-
# @api private
|
|
37
|
-
# @since 0.1.0
|
|
38
|
-
# @version 0.8.0
|
|
39
|
-
def initialize(root_reconciler, schema_key, &nested_definitions)
|
|
40
|
-
@root_reconciler = root_reconciler
|
|
41
|
-
@schema_key = SmartCore::Schema::KeyControl.normalize(schema_key)
|
|
42
|
-
@options = SmartCore::Schema::Checker::Rules::Options.new(self)
|
|
43
|
-
@nested_reconciler = nil
|
|
44
|
-
define_nested_reconciler(&nested_definitions)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# @!method requirement
|
|
48
|
-
# @return [SmartCore::Schema::Checker::Rules::Requirement::Optional]
|
|
49
|
-
# @return [SmartCore::Schema::Checker::Rules::Requirement::Required]
|
|
50
|
-
|
|
51
|
-
# @param verifiable_hash [Hash<String|Symbol,Any>]
|
|
52
|
-
# @param matcher_options [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
53
|
-
# @return [SmartCore::Schema::Checker::Rules::Verifier::Result]
|
|
54
|
-
#
|
|
55
|
-
# @api private
|
|
56
|
-
# @since 0.1.0
|
|
57
|
-
# @version 0.3.0
|
|
58
|
-
def __verify!(verifiable_hash, matcher_options)
|
|
59
|
-
SmartCore::Schema::Checker::Rules::Verifier.verify!(
|
|
60
|
-
self, matcher_options, verifiable_hash
|
|
61
|
-
)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# @param required_type [String, Symbol, SmartCore::Types::Primitive]
|
|
65
|
-
# @param nested_definitions [Block]
|
|
66
|
-
# @return [self]
|
|
67
|
-
#
|
|
68
|
-
# @api public
|
|
69
|
-
# @since 0.1.0
|
|
70
|
-
# @version 0.8.0
|
|
71
|
-
def type(required_type, &nested_definitions)
|
|
72
|
-
tap do
|
|
73
|
-
options.type = SmartCore::Schema::Checker::Rules::Options::Type.new(self, required_type)
|
|
74
|
-
define_nested_reconciler(&nested_definitions)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# @param nested_definitions [Block]
|
|
79
|
-
# @return [self]
|
|
80
|
-
#
|
|
81
|
-
# @api public
|
|
82
|
-
# @since 0.1.0
|
|
83
|
-
# @version 0.8.0
|
|
84
|
-
def filled(&nested_definitions)
|
|
85
|
-
tap do
|
|
86
|
-
options.filled = SmartCore::Schema::Checker::Rules::Options::Filled.new(self)
|
|
87
|
-
define_nested_reconciler(&nested_definitions)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
private
|
|
92
|
-
|
|
93
|
-
# @param nested_definitions [Block]
|
|
94
|
-
# @return [void]
|
|
95
|
-
#
|
|
96
|
-
# @api private
|
|
97
|
-
# @since 0.1.0
|
|
98
|
-
# @version 0.3.0
|
|
99
|
-
def define_nested_reconciler(&nested_definitions)
|
|
100
|
-
return unless block_given?
|
|
101
|
-
|
|
102
|
-
SmartCore::Schema::Checker::Reconciler::Constructor.tap do |constructor|
|
|
103
|
-
@nested_reconciler = constructor.create if @nested_reconciler == nil
|
|
104
|
-
@nested_reconciler.strict!(root_reconciler.__strict?)
|
|
105
|
-
constructor.append_definitions(@nested_reconciler, &nested_definitions)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
type(:hash).filled
|
|
109
|
-
end
|
|
110
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module SmartCore::Schema::Checker::Rules::ExtraKeys
|
|
4
|
-
# @api private
|
|
5
|
-
# @since 0.1.0
|
|
6
|
-
# @version 0.3.0
|
|
7
|
-
class Failure < Result
|
|
8
|
-
# @return [Boolean]
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
# @since 0.1.0
|
|
12
|
-
def success?
|
|
13
|
-
false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# @return [Boolean]
|
|
17
|
-
#
|
|
18
|
-
# @api private
|
|
19
|
-
# @since 0.1.0
|
|
20
|
-
def failure?
|
|
21
|
-
true
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @apbstract
|
|
4
|
-
#
|
|
5
|
-
# @api private
|
|
6
|
-
# @since 0.3.0
|
|
7
|
-
class SmartCore::Schema::Checker::Rules::ExtraKeys::Result
|
|
8
|
-
# @return [Array<String>]
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
# @since 0.3.0
|
|
12
|
-
attr_reader :extra_keys
|
|
13
|
-
|
|
14
|
-
# @return [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
15
|
-
#
|
|
16
|
-
# @api private
|
|
17
|
-
# @since 0.3.0
|
|
18
|
-
attr_reader :matcher_options
|
|
19
|
-
|
|
20
|
-
# @param extra_keys [Array<String>]
|
|
21
|
-
# @param matcher_options [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
22
|
-
# @return [void]
|
|
23
|
-
#
|
|
24
|
-
# @api private
|
|
25
|
-
# @since 0.1.0
|
|
26
|
-
# @version 0.3.0
|
|
27
|
-
def initialize(extra_keys, matcher_options)
|
|
28
|
-
@extra_keys = extra_keys
|
|
29
|
-
@matcher_options = matcher_options
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# @!method success?
|
|
33
|
-
# @return [Boolean]
|
|
34
|
-
|
|
35
|
-
# @!method failure?
|
|
36
|
-
# @return [Boolean]
|
|
37
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module SmartCore::Schema::Checker::Rules::ExtraKeys
|
|
4
|
-
# @api private
|
|
5
|
-
# @since 0.1.0
|
|
6
|
-
# @version 0.3.0
|
|
7
|
-
class Success < Result
|
|
8
|
-
# @return [Array<String>]
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
# @since 0.3.0
|
|
12
|
-
alias_method :spread_keys, :extra_keys
|
|
13
|
-
|
|
14
|
-
# @return [Boolean]
|
|
15
|
-
#
|
|
16
|
-
# @api private
|
|
17
|
-
# @since 0.1.0
|
|
18
|
-
def success?
|
|
19
|
-
true
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# @return [Boolean]
|
|
23
|
-
#
|
|
24
|
-
# @api private
|
|
25
|
-
# @since 0.1.0
|
|
26
|
-
def failure?
|
|
27
|
-
false
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
# @version 0.3.0
|
|
6
|
-
module SmartCore::Schema::Checker::Rules::ExtraKeys
|
|
7
|
-
require_relative 'extra_keys/result'
|
|
8
|
-
require_relative 'extra_keys/success'
|
|
9
|
-
require_relative 'extra_keys/failure'
|
|
10
|
-
|
|
11
|
-
class << self
|
|
12
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
13
|
-
# @param rules [SmartCore::Schema::Checker::Rules]
|
|
14
|
-
# @param matcher_options [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
15
|
-
# @return [SmartCore::Schema::Checker::Rules::ExtraKeys::Success]
|
|
16
|
-
# @return [SmartCore::Schema::Checker::Rules::ExtraKeys::Failure]
|
|
17
|
-
#
|
|
18
|
-
# @api private
|
|
19
|
-
# @since 0.1.0
|
|
20
|
-
# @version 0.3.0
|
|
21
|
-
def __verify!(verifiable_hash, rules, matcher_options)
|
|
22
|
-
extra_keys = verifiable_hash.keys - rules.keys
|
|
23
|
-
|
|
24
|
-
if extra_keys.empty? || (extra_keys.any? && !matcher_options.strict_schema?)
|
|
25
|
-
Success.new(extra_keys, matcher_options)
|
|
26
|
-
else
|
|
27
|
-
Failure.new(extra_keys, matcher_options)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
# @version 0.3.0
|
|
6
|
-
class SmartCore::Schema::Checker::Rules::Optional < SmartCore::Schema::Checker::Rules::Base
|
|
7
|
-
# @return [SmartCore::Schema::Checker::Rules::Requirement::Optional]
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
# @since 0.1.0
|
|
11
|
-
attr_reader :requirement
|
|
12
|
-
|
|
13
|
-
# @param root_reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
14
|
-
# @param schema_key [String, Symbol]
|
|
15
|
-
# @param nested_definitions [Block]
|
|
16
|
-
# @return [void]
|
|
17
|
-
#
|
|
18
|
-
# @api private
|
|
19
|
-
# @since 0.1.0
|
|
20
|
-
# @version 0.3.0
|
|
21
|
-
# rubocop:disable Style/SuperArguments
|
|
22
|
-
def initialize(root_reconciler, schema_key, &nested_definitions)
|
|
23
|
-
super(root_reconciler, schema_key, &nested_definitions)
|
|
24
|
-
@requirement = SmartCore::Schema::Checker::Rules::Requirement::Optional.new(self)
|
|
25
|
-
end
|
|
26
|
-
# rubocop:enable Style/SuperArguments
|
|
27
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
class SmartCore::Schema::Checker::Rules::Options::Empty
|
|
6
|
-
# @since 0.1.0
|
|
7
|
-
extend Forwardable
|
|
8
|
-
|
|
9
|
-
# @param rule [SmartCore::Schema::Checker::Rules::Base]
|
|
10
|
-
# @return [void]
|
|
11
|
-
#
|
|
12
|
-
# @api private
|
|
13
|
-
# @since 0.1.0
|
|
14
|
-
def initialize(rule)
|
|
15
|
-
@rule = rule
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
19
|
-
# @return [SmartCore::Schema::Checker::Rules::Result::Success]
|
|
20
|
-
#
|
|
21
|
-
# @api private
|
|
22
|
-
# @since 0.1.0
|
|
23
|
-
def validate(verifiable_hash)
|
|
24
|
-
SmartCore::Schema::Checker::Rules::Result::Success.new(
|
|
25
|
-
key: schema_key,
|
|
26
|
-
value: verifiable_hash[schema_key]
|
|
27
|
-
)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
# @return [SmartCore::Schema::Checker::Rules::Base]
|
|
33
|
-
#
|
|
34
|
-
# @api private
|
|
35
|
-
# @since 0.1.0
|
|
36
|
-
attr_reader :rule
|
|
37
|
-
|
|
38
|
-
# @return [String]
|
|
39
|
-
#
|
|
40
|
-
# @api private
|
|
41
|
-
# @since 0.1.0
|
|
42
|
-
def_delegator :rule, :schema_key
|
|
43
|
-
end
|