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
data/README.md
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
# SmartCore::Schema · <a target="_blank" href="https://github.com/Cado-Labs"><img src="https://github.com/Cado-Labs/cado-labs-logos/raw/main/cado_labs_badge.svg" alt="Supported by Cado Labs" style="max-width: 100%; height: 20px"></a> · [](https://badge.fury.io/rb/smart_schema)
|
|
2
|
-
|
|
3
|
-
`SmartCore::Schema` is a schema validator for `Hash`-like data structures (`Array`-like - coming soon) in declarative DSL-powered style.
|
|
4
|
-
|
|
5
|
-
Provides convenient and concise DSL to define complex schemas in easiest way and public validation interface to achieve a comfortable work with detailed validation result.
|
|
6
|
-
|
|
7
|
-
Supports nested structures, type validation (via `smart_types`), required- and optional- schema keys, *strict* and *non-strict* schemas, schema value presence validation, schema inheritance (soon), schema extending (soon) and schema composition (soon).
|
|
8
|
-
|
|
9
|
-
Works in predicate style and in OOP/Monadic result object style. Enjoy :)
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
<p>
|
|
14
|
-
<a href="https://github.com/Cado-Labs">
|
|
15
|
-
<img src="https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_supporting.svg" alt="Supported by Cado Labs" />
|
|
16
|
-
</a>
|
|
17
|
-
</p>
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
|
|
23
|
-
```ruby
|
|
24
|
-
gem 'smart_schema'
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
```shell
|
|
28
|
-
bundle install
|
|
29
|
-
# --- or ---
|
|
30
|
-
gem install smart_schema
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
```ruby
|
|
34
|
-
require 'smart_core/schema'
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## Synopsis
|
|
40
|
-
|
|
41
|
-
- key requirement: `required` and `optional`;
|
|
42
|
-
- type validation: `type`;
|
|
43
|
-
- `nil` control: `filled`;
|
|
44
|
-
- nested definitions: `do ... end`;
|
|
45
|
-
- supported types: see `smart_types` gem;
|
|
46
|
-
- strict modes and strict behavior: `strict!`, `non_strict!`, `schema(:strict)`, `schema(:non_strict)`;
|
|
47
|
-
- `:strict` is used by default (in first `schema` invokation);
|
|
48
|
-
- you can make non-strict inner schemas inside strict schemas (and vise-versa);
|
|
49
|
-
- inner schemas inherits their's mode from their's nearest outer schema (and can have own mode too);
|
|
50
|
-
|
|
51
|
-
```ruby
|
|
52
|
-
class MySchema < SmartCore::Schema
|
|
53
|
-
# you can mark strict mode in root schema here:
|
|
54
|
-
#
|
|
55
|
-
# non_strict!
|
|
56
|
-
#
|
|
57
|
-
# -- or --
|
|
58
|
-
#
|
|
59
|
-
# strict!
|
|
60
|
-
|
|
61
|
-
schema do # or here with `schema(:strict)` (default in first time) or `schema(:non_strict)`
|
|
62
|
-
required(:key) do
|
|
63
|
-
# inherits `:strict`
|
|
64
|
-
optional(:data).type(:string).filled
|
|
65
|
-
optional(:value).type(:numeric)
|
|
66
|
-
required(:name).type(:string)
|
|
67
|
-
|
|
68
|
-
required(:nested) do
|
|
69
|
-
# inherits `:strict`
|
|
70
|
-
optional(:version).filled
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
optional(:another_nested) do
|
|
74
|
-
non_strict! # marks current nested schema as `:non_strict`
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
required(:another_key).filled
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
```ruby
|
|
84
|
-
# you can open already defined schema and continue schema definitioning:
|
|
85
|
-
|
|
86
|
-
schema do
|
|
87
|
-
required(:third_key).filled.type(:string)
|
|
88
|
-
end
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
```ruby
|
|
92
|
-
# you can redefine strict behavior of already defined schema:
|
|
93
|
-
|
|
94
|
-
schema(:non_strict) do
|
|
95
|
-
# ...
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# -- or --
|
|
99
|
-
schema do
|
|
100
|
-
non_strict!
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# -- or --
|
|
104
|
-
non_strict!
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
```ruby
|
|
108
|
-
# you can redefine nested schema behavior:
|
|
109
|
-
|
|
110
|
-
schema do
|
|
111
|
-
optional(:another_nested) do
|
|
112
|
-
strict! # change from :non_strict to :strict
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
```ruby
|
|
118
|
-
MySchema.new.valid?({
|
|
119
|
-
key: {
|
|
120
|
-
data: '5',
|
|
121
|
-
value: 1,
|
|
122
|
-
name: 'D@iVeR'
|
|
123
|
-
nested: {}
|
|
124
|
-
}
|
|
125
|
-
another_key: true
|
|
126
|
-
}) # => true
|
|
127
|
-
|
|
128
|
-
MySchema.new.valid?({
|
|
129
|
-
key: {
|
|
130
|
-
data: nil,
|
|
131
|
-
value: 1,
|
|
132
|
-
name: 'D@iVeR'
|
|
133
|
-
nested: {}
|
|
134
|
-
}
|
|
135
|
-
}) # => false (missing :another_key, key->data is not filled)
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
```ruby
|
|
139
|
-
result = MySchema.new.validate(
|
|
140
|
-
key: { data: nil, value: '1', name: 'D@iVeR' },
|
|
141
|
-
another_key: nil,
|
|
142
|
-
third_key: 'test'
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
# => outputs:
|
|
146
|
-
# #<SmartCore::Schema::Result:0x00007ffcd8926990
|
|
147
|
-
# @errors={"key.data"=>[:non_filled], "key.value"=>[:invalid_type], "key.nested"=>[:required_key_not_found], "another_key"=>[:non_filled], "third_key"=>[:extra_key]},
|
|
148
|
-
# @extra_keys=#<Set: {"third_key"}>,
|
|
149
|
-
# @spread_keys=#<Set: {}>, (coming soon (spread keys of non-strict schemas))
|
|
150
|
-
# @source={:key=>{:data=>nil, :value=>"1", :name=>"D@iVeR"}, :another_key=>nil, :third_key=>"test"}>
|
|
151
|
-
|
|
152
|
-
result.success? # => false
|
|
153
|
-
result.spread_keys # => <Set: {}> (coming soon (spread keys of non-strict schemas))
|
|
154
|
-
result.extra_keys # => <Set: {"third_key"}>
|
|
155
|
-
result.errors # =>
|
|
156
|
-
{
|
|
157
|
-
"key.data"=>[:non_filled],
|
|
158
|
-
"key.value"=>[:invalid_type],
|
|
159
|
-
"key.nested"=>[:required_key_not_found],
|
|
160
|
-
"another_key"=>[:non_filled],
|
|
161
|
-
"third_key"=>[:extra_key]
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Possible errors:
|
|
166
|
-
- `:non_filled` (existing key has nil value);
|
|
167
|
-
- `:invalid_type` (existing key has invalid type);
|
|
168
|
-
- `:required_key_not_found` (required key does not exist);
|
|
169
|
-
- `:extra_key` (concrete key does not exist in schema);
|
|
170
|
-
|
|
171
|
-
## Type System Customization
|
|
172
|
-
|
|
173
|
-
- supports `smart-types` (pre-configured by default);
|
|
174
|
-
- supports `dry-types` (requires `dry-types` gem required in your project);
|
|
175
|
-
- configuration has a global effect (single type-config for all Schema instances/classes)
|
|
176
|
-
- **NOTE**: this behavior will be reworked in future (mutliple type system support at once);
|
|
177
|
-
|
|
178
|
-
### Type System Configuration and Usage
|
|
179
|
-
|
|
180
|
-
```ruby
|
|
181
|
-
# IMPORTANT: inn order to use dry-types:
|
|
182
|
-
# 1. you should install dry-types and require dry-types in your projecgts
|
|
183
|
-
# 2. require dry_types plugin
|
|
184
|
-
|
|
185
|
-
require 'dry-types'
|
|
186
|
-
SmartCore::Schema.plugin(:dry_types) # fails if you try to enable this plugin without a pre-isntalled dry-types;
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
```ruby
|
|
190
|
-
SmartCore::Schema::Configuration.configure do |config|
|
|
191
|
-
config.type_system = :dry_types # :smart_types (:smart_types is used by default)
|
|
192
|
-
end
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
```ruby
|
|
196
|
-
# configure type aliases
|
|
197
|
-
|
|
198
|
-
# - for smart-types
|
|
199
|
-
SmartCore::Schema.type_system.type_alias(:integer, SmartCore::Types::Value::Integer)
|
|
200
|
-
# smart-types has a list of pre-configured aliases. see lib/smart_core/schema/type_system/smart_types.rb
|
|
201
|
-
|
|
202
|
-
# - for dry-types
|
|
203
|
-
SmartCore::Schema.type_system.type_alias(:integer, Dry::Types['integer'])
|
|
204
|
-
# dry-types has no pre-configured aliases.
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
```ruby
|
|
208
|
-
# classic smart-types usage
|
|
209
|
-
class MySchemaWithSmartTypes < SmartCore::Schema
|
|
210
|
-
schema do
|
|
211
|
-
required(:date).type(SmartCore::Types::Value::String) # object-style
|
|
212
|
-
required(:count).type(:integer) # alias-style
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
# dry-types usage
|
|
217
|
-
class MySchemaWithDryTypes < SmartCore::Schema
|
|
218
|
-
schema do
|
|
219
|
-
required(:date).type(Dry::Types['string']) # object-style
|
|
220
|
-
required(:count).type(:integer) # alias-style
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## Roadmap
|
|
228
|
-
|
|
229
|
-
- **(x.x.x)** - **(As Soon As Possible)** support for schema inhertiance with schema redefinition ;
|
|
230
|
-
- **(x.x.x)** - support for `.cast` in type definitions;
|
|
231
|
-
- **(x.x.x)** - mutable schemas (value convertion during schema checking with returning the new coerced data structure);
|
|
232
|
-
- **(x.x.x)** - public interface for type aliasing (custom type alias registration API);
|
|
233
|
-
- **(x.x.x)** - support for `Array`-like data structures;
|
|
234
|
-
- **(0.x.0)** - an abiltiy to represent the required schema as a string (conviniet way to check what schema is defained internally when we work wtih a dynamic schema definition or in a console);
|
|
235
|
-
- **(0.x.0)** - migrate to `GitHub Actions` (CI);
|
|
236
|
-
- **(0.x.0)** - value-validation layer;
|
|
237
|
-
- **(0.x.0)** - error messages (that are consistent with error codes), with a support for error-code-auto-mappings for error messages via explicit hashes or via file (yaml, json and other formats);
|
|
238
|
-
- **(0.6.0)** - support for `Array`-type in schema definition;
|
|
239
|
-
- **(0.6.0)** - spread keys of non-strict schemas in validation result;
|
|
240
|
-
- **(0.7.0)** - schema inheritance;
|
|
241
|
-
- **(0.7.0)** - schema composition (`required(:key).schema(SchemaClass)`) (`compose_with(AnotherSchema)`);
|
|
242
|
-
- **(0.7.0)** - dependable schema checking (sample: if one key exist (or not) we should check another (or not), and vice verca) (mb `if(:_key_)` rule);
|
|
243
|
-
- **(0.8.0)** - `smart_type-system` integration;
|
|
244
|
-
- **(0.9.0)** - support for another data structures (such as YAML strings, JSON strings, `Struct`, `OpenStruct`s, custom `Object`s and etc);
|
|
245
|
-
- **(0.10.0)** - mixin-based implementation;
|
|
246
|
-
- **(0.x.0)** - think about pattern matching;
|
|
247
|
-
- **(0.x.0)** - dependable schema checks: we can conditionally check some parts of schema stracture that depends on schema key values;
|
|
248
|
-
- **(0.x.0)** - support for dynamic keys, when the key name can have any name and can be a value or a schema;
|
|
249
|
-
```ruby
|
|
250
|
-
# PROPOSAL:
|
|
251
|
-
|
|
252
|
-
required(:some_key) do
|
|
253
|
-
dynamic do # dynamic schema
|
|
254
|
-
required(:kek).type(:string).filled
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
dynamic.type(:integer).filled # dynamic key
|
|
258
|
-
end
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
---
|
|
262
|
-
|
|
263
|
-
## Build
|
|
264
|
-
|
|
265
|
-
- run tests:
|
|
266
|
-
|
|
267
|
-
```shell
|
|
268
|
-
bundle exec rake rspec
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
- run code style checks:
|
|
272
|
-
|
|
273
|
-
```shell
|
|
274
|
-
bundle exec rake rubocop
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
- run code style checks with auto-correction:
|
|
278
|
-
|
|
279
|
-
```shell
|
|
280
|
-
bundle exec rake rubocop -A
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
## Contributing
|
|
286
|
-
|
|
287
|
-
- Fork it ( https://github.com/smart-rb/smart_schema )
|
|
288
|
-
- Create your feature branch (`git checkout -b feature/my-new-feature`)
|
|
289
|
-
- Commit your changes (`git commit -am '[feature_context] Add some feature'`)
|
|
290
|
-
- Push to the branch (`git push origin feature/my-new-feature`)
|
|
291
|
-
- Create new Pull Request
|
|
292
|
-
|
|
293
|
-
## License
|
|
294
|
-
|
|
295
|
-
Released under MIT License.
|
|
296
|
-
|
|
297
|
-
## Supporting
|
|
298
|
-
|
|
299
|
-
<a href="https://github.com/Cado-Labs">
|
|
300
|
-
<img src="https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_logo.png" alt="Supported by Cado Labs" />
|
|
301
|
-
</a>
|
|
302
|
-
|
|
303
|
-
## Authors
|
|
304
|
-
|
|
305
|
-
[Rustam Ibragimov](https://github.com/0exp)
|
data/Rakefile
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'bundler/gem_tasks'
|
|
4
|
-
require 'rspec/core/rake_task'
|
|
5
|
-
require 'rubocop'
|
|
6
|
-
require 'rubocop/rake_task'
|
|
7
|
-
require 'rubocop-performance'
|
|
8
|
-
require 'rubocop-rspec'
|
|
9
|
-
require 'rubocop-rake'
|
|
10
|
-
|
|
11
|
-
RuboCop::RakeTask.new(:rubocop) do |t|
|
|
12
|
-
config_path = File.expand_path(File.join('.rubocop.yml'), __dir__)
|
|
13
|
-
t.options = ['--config', config_path]
|
|
14
|
-
t.requires << 'rubocop-rspec'
|
|
15
|
-
t.requires << 'rubocop-performance'
|
|
16
|
-
t.requires << 'rubocop-rake'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
RSpec::Core::RakeTask.new(:rspec)
|
|
20
|
-
|
|
21
|
-
task default: :rspec
|
data/bin/console
DELETED
data/bin/setup
DELETED
|
@@ -1,60 +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::Constructor
|
|
7
|
-
# @return [Hash<String,Boolean>]
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
# @since 0.3.0
|
|
11
|
-
STRICT_MODES = { strict: true, 'strict' => true, non_strict: false, 'non_strict' => true }.freeze
|
|
12
|
-
|
|
13
|
-
# @return [Boolean]
|
|
14
|
-
#
|
|
15
|
-
# @pai private
|
|
16
|
-
# @since 0.3.0
|
|
17
|
-
DEFAULT_STRICT_BEHAVIOR = STRICT_MODES[:strict] # NOTE: means `strict by default`
|
|
18
|
-
|
|
19
|
-
class << self
|
|
20
|
-
# @param reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
21
|
-
# @param definitions [Proc]
|
|
22
|
-
# @return [void]
|
|
23
|
-
#
|
|
24
|
-
# @api private
|
|
25
|
-
# @since 0.1.0
|
|
26
|
-
def append_definitions(reconciler, &definitions)
|
|
27
|
-
reconciler.instance_eval(&definitions)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# @param reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
31
|
-
# @param strict_mode [NilClass, String, Symbol]
|
|
32
|
-
# @return [void]
|
|
33
|
-
#
|
|
34
|
-
# @api private
|
|
35
|
-
# @since 0.3.0
|
|
36
|
-
def set_strict_mode(reconciler, strict_mode)
|
|
37
|
-
return if strict_mode == nil
|
|
38
|
-
|
|
39
|
-
is_strict = STRICT_MODES.fetch(strict_mode) do
|
|
40
|
-
raise(SmartCore::Schema::ArgumentError, <<~ERROR_MESSAGE)
|
|
41
|
-
Unsupported strict mode "#{strict_mode}".
|
|
42
|
-
SmartCore::Schema supports "strict" and "non_strict" modes only.
|
|
43
|
-
ERROR_MESSAGE
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
reconciler.strict!(is_strict)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# @param definitions [Proc, NilClass]
|
|
50
|
-
# @return [SmarCore::Schema::Checker::Reconciler]
|
|
51
|
-
#
|
|
52
|
-
# @api private
|
|
53
|
-
# @since 0.1.0
|
|
54
|
-
def create(&definitions)
|
|
55
|
-
SmartCore::Schema::Checker::Reconciler.new.tap do |reconciler|
|
|
56
|
-
append_definitions(reconciler, &definitions) if block_given?
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.3.0
|
|
5
|
-
class SmartCore::Schema::Checker::Reconciler::Matcher::Options
|
|
6
|
-
class << self
|
|
7
|
-
# @param reconciler [SmartCore::Schema::Checker::Reconciler]
|
|
8
|
-
# @return [SmartCore::Schema::Checker::Reconciler::Matcher::Options]
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
# @since 0.3.0
|
|
12
|
-
def build_from(reconciler)
|
|
13
|
-
new(reconciler.__strict?)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# @param is_strict_schema [Boolean]
|
|
18
|
-
# @return [void]
|
|
19
|
-
#
|
|
20
|
-
# @api private
|
|
21
|
-
# @since 0.3.0
|
|
22
|
-
def initialize(is_strict_schema)
|
|
23
|
-
@is_strict_schema = is_strict_schema
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# @return [Boolean]
|
|
27
|
-
#
|
|
28
|
-
# @api private
|
|
29
|
-
# @since 0.3.0
|
|
30
|
-
def strict_schema?
|
|
31
|
-
@is_strict_schema
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,87 +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::Matcher::Result
|
|
7
|
-
# @return [Hash<String|Symbol,Any>]
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
# @since 0.1.0
|
|
11
|
-
attr_reader :verifiable_hash
|
|
12
|
-
|
|
13
|
-
# @return [SmartCore::Schema::Checker::Rules::Verifier::Result]
|
|
14
|
-
#
|
|
15
|
-
# @api private
|
|
16
|
-
# @since 0.1.0
|
|
17
|
-
attr_reader :contract_keys_results
|
|
18
|
-
|
|
19
|
-
# @return [
|
|
20
|
-
# SmartCore::Schema::Checker::Rules::ExtraKeys::Success,
|
|
21
|
-
# SmartCore::Schema::Checker::Rules::ExtraKeys::Failure
|
|
22
|
-
# ]
|
|
23
|
-
# @api private
|
|
24
|
-
# @since 0.1.0
|
|
25
|
-
attr_reader :extra_keys_results
|
|
26
|
-
|
|
27
|
-
# @param verifiable_hash [SmartCore::Schema::Checker::VerifiableHash]
|
|
28
|
-
# @return [void]
|
|
29
|
-
#
|
|
30
|
-
# @api private
|
|
31
|
-
# @since 0.1.0
|
|
32
|
-
# @version 0.8.0
|
|
33
|
-
def initialize(verifiable_hash)
|
|
34
|
-
@verifiable_hash = verifiable_hash
|
|
35
|
-
@contract_keys_results = []
|
|
36
|
-
@extra_keys_results = []
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# @param block
|
|
40
|
-
# @yield [result]
|
|
41
|
-
# @yieldparam result [
|
|
42
|
-
# SmartCore::Schema::Checker::Rules::Verifier::Result,
|
|
43
|
-
# SmartCore::Schema::Checker::Rules::ExtraKeys::Success,
|
|
44
|
-
# SmartCore::Schema::Checker::Rules::ExtraKeys::Failure
|
|
45
|
-
# ]
|
|
46
|
-
# @return [void]
|
|
47
|
-
#
|
|
48
|
-
# @api private
|
|
49
|
-
# @since 0.1.0
|
|
50
|
-
# @version 0.8.0
|
|
51
|
-
def each_result(&block)
|
|
52
|
-
contract_keys_results.each(&block)
|
|
53
|
-
extra_keys_results.each(&block)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# @param result [SmartCore::Schema::Checker::Rules::Verifier::Result]
|
|
57
|
-
# @return [void]
|
|
58
|
-
#
|
|
59
|
-
# @api private
|
|
60
|
-
# @since 0.1.0
|
|
61
|
-
# @version 0.8.0
|
|
62
|
-
def contract_key_result(result)
|
|
63
|
-
contract_keys_results << result
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# @param result [
|
|
67
|
-
# SmartCore::Schema::Checker::Rules::ExtraKeys::Success,
|
|
68
|
-
# SmartCore::Schema::Checker::Rules::ExtraKeys::Failure
|
|
69
|
-
# ]
|
|
70
|
-
# @return [void]
|
|
71
|
-
#
|
|
72
|
-
# @api private
|
|
73
|
-
# @since 0.1.0
|
|
74
|
-
# @version 0.8.0
|
|
75
|
-
def extra_keys_result(result)
|
|
76
|
-
extra_keys_results << result
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# @return [SmartCore::Schema::Result]
|
|
80
|
-
#
|
|
81
|
-
# @api private
|
|
82
|
-
# @since 0.1.0
|
|
83
|
-
# @version 0.8.0
|
|
84
|
-
def complete!
|
|
85
|
-
SmartCore::Schema::Checker::Reconciler::Matcher::ResultFinalizer.finalize(self)
|
|
86
|
-
end
|
|
87
|
-
end
|