smart_schema 0.1.0 → 0.2.0
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
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +41 -39
- data/README.md +16 -8
- data/lib/smart_core/schema/checker/reconciler/matcher/result_finalizer.rb +15 -2
- data/lib/smart_core/schema/checker/rules/type_aliases.rb +5 -1
- data/lib/smart_core/schema/version.rb +2 -2
- data/smart_schema.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a86fa55dff1a9608dd4bd87eccb26eb9f9cf7ea1fd5699e800754d1c006814d
|
|
4
|
+
data.tar.gz: 1bcdce646a6ea5db5494493c024bff6fbdab390bcc4445d7801047a644c272cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 17f908f2ddcc72d096093af737b9b80214d3f0cbca2fd7064e95b81036731e9f94205cad5b5a8db25c4eac3b61bb22a1e670f7f3876540b9c73518da5fc279ad
|
|
7
|
+
data.tar.gz: 17361851cca2d1d4380ceb82c8fc3a138203fc075ac5286a1de87ab9e0fcf76dd095b6aa2d61347a89157aea806404ec5cd2347641f313dbb0ad8ac4faacdabc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
# [0.2.0] - 2020-11-09
|
|
5
|
+
### Added
|
|
6
|
+
- `#errors` now includes `#extra_keys` too (`:extra_key` error code for each extra key);
|
|
7
|
+
- Unfreezed `SmartCore::Schema::Checker::Rules::TYPE_ALIASES` for extendability (until `smart_type-syste` has been integrated);
|
|
8
|
+
|
|
4
9
|
# [0.1.0] - 2020-08-25
|
|
5
10
|
|
|
6
11
|
- Release :)
|
data/Gemfile.lock
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
smart_schema (0.
|
|
4
|
+
smart_schema (0.2.0)
|
|
5
5
|
smart_engine (~> 0.8)
|
|
6
6
|
smart_types (~> 0.1)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activesupport (6.0.3.
|
|
11
|
+
activesupport (6.0.3.4)
|
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
13
|
i18n (>= 0.7, < 2)
|
|
14
14
|
minitest (~> 5.1)
|
|
15
15
|
tzinfo (~> 1.1)
|
|
16
16
|
zeitwerk (~> 2.2, >= 2.2.2)
|
|
17
|
-
armitage-rubocop (
|
|
18
|
-
rubocop (=
|
|
19
|
-
rubocop-performance (= 1.
|
|
20
|
-
rubocop-rails (= 2.
|
|
17
|
+
armitage-rubocop (1.2.0)
|
|
18
|
+
rubocop (= 1.2.0)
|
|
19
|
+
rubocop-performance (= 1.8.1)
|
|
20
|
+
rubocop-rails (= 2.8.1)
|
|
21
21
|
rubocop-rake (= 0.5.1)
|
|
22
|
-
rubocop-rspec (=
|
|
22
|
+
rubocop-rspec (= 2.0.0)
|
|
23
23
|
ast (2.4.1)
|
|
24
24
|
coderay (1.1.3)
|
|
25
25
|
concurrent-ruby (1.1.7)
|
|
@@ -28,9 +28,9 @@ GEM
|
|
|
28
28
|
i18n (1.8.5)
|
|
29
29
|
concurrent-ruby (~> 1.0)
|
|
30
30
|
method_source (1.0.0)
|
|
31
|
-
minitest (5.14.
|
|
32
|
-
parallel (1.
|
|
33
|
-
parser (2.7.
|
|
31
|
+
minitest (5.14.2)
|
|
32
|
+
parallel (1.20.0)
|
|
33
|
+
parser (2.7.2.0)
|
|
34
34
|
ast (~> 2.4.1)
|
|
35
35
|
pry (0.13.1)
|
|
36
36
|
coderay (~> 1.1)
|
|
@@ -38,65 +38,67 @@ GEM
|
|
|
38
38
|
rack (2.2.3)
|
|
39
39
|
rainbow (3.0.0)
|
|
40
40
|
rake (13.0.1)
|
|
41
|
-
regexp_parser (1.
|
|
41
|
+
regexp_parser (1.8.2)
|
|
42
42
|
rexml (3.2.4)
|
|
43
|
-
rspec (3.
|
|
44
|
-
rspec-core (~> 3.
|
|
45
|
-
rspec-expectations (~> 3.
|
|
46
|
-
rspec-mocks (~> 3.
|
|
47
|
-
rspec-core (3.
|
|
48
|
-
rspec-support (~> 3.
|
|
49
|
-
rspec-expectations (3.
|
|
43
|
+
rspec (3.10.0)
|
|
44
|
+
rspec-core (~> 3.10.0)
|
|
45
|
+
rspec-expectations (~> 3.10.0)
|
|
46
|
+
rspec-mocks (~> 3.10.0)
|
|
47
|
+
rspec-core (3.10.0)
|
|
48
|
+
rspec-support (~> 3.10.0)
|
|
49
|
+
rspec-expectations (3.10.0)
|
|
50
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
51
|
-
rspec-support (~> 3.
|
|
52
|
-
rspec-mocks (3.
|
|
51
|
+
rspec-support (~> 3.10.0)
|
|
52
|
+
rspec-mocks (3.10.0)
|
|
53
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
54
|
-
rspec-support (~> 3.
|
|
55
|
-
rspec-support (3.
|
|
56
|
-
rubocop (
|
|
54
|
+
rspec-support (~> 3.10.0)
|
|
55
|
+
rspec-support (3.10.0)
|
|
56
|
+
rubocop (1.2.0)
|
|
57
57
|
parallel (~> 1.10)
|
|
58
|
-
parser (>= 2.7.1.
|
|
58
|
+
parser (>= 2.7.1.5)
|
|
59
59
|
rainbow (>= 2.2.2, < 4.0)
|
|
60
|
-
regexp_parser (>= 1.
|
|
60
|
+
regexp_parser (>= 1.8)
|
|
61
61
|
rexml
|
|
62
|
-
rubocop-ast (>= 0.
|
|
62
|
+
rubocop-ast (>= 1.0.1)
|
|
63
63
|
ruby-progressbar (~> 1.7)
|
|
64
64
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
65
|
-
rubocop-ast (
|
|
66
|
-
parser (>= 2.7.1.
|
|
67
|
-
rubocop-performance (1.
|
|
68
|
-
rubocop (>= 0.
|
|
69
|
-
|
|
65
|
+
rubocop-ast (1.1.1)
|
|
66
|
+
parser (>= 2.7.1.5)
|
|
67
|
+
rubocop-performance (1.8.1)
|
|
68
|
+
rubocop (>= 0.87.0)
|
|
69
|
+
rubocop-ast (>= 0.4.0)
|
|
70
|
+
rubocop-rails (2.8.1)
|
|
70
71
|
activesupport (>= 4.2.0)
|
|
71
72
|
rack (>= 1.1)
|
|
72
73
|
rubocop (>= 0.87.0)
|
|
73
74
|
rubocop-rake (0.5.1)
|
|
74
75
|
rubocop
|
|
75
|
-
rubocop-rspec (
|
|
76
|
-
rubocop (~> 0
|
|
76
|
+
rubocop-rspec (2.0.0)
|
|
77
|
+
rubocop (~> 1.0)
|
|
78
|
+
rubocop-ast (>= 1.1.0)
|
|
77
79
|
ruby-progressbar (1.10.1)
|
|
78
|
-
simplecov (0.19.
|
|
80
|
+
simplecov (0.19.1)
|
|
79
81
|
docile (~> 1.1)
|
|
80
82
|
simplecov-html (~> 0.11)
|
|
81
|
-
simplecov-html (0.12.
|
|
83
|
+
simplecov-html (0.12.3)
|
|
82
84
|
smart_engine (0.8.0)
|
|
83
85
|
smart_types (0.1.0)
|
|
84
86
|
smart_engine (~> 0.6)
|
|
85
87
|
thread_safe (0.3.6)
|
|
86
|
-
tzinfo (1.2.
|
|
88
|
+
tzinfo (1.2.8)
|
|
87
89
|
thread_safe (~> 0.1)
|
|
88
90
|
unicode-display_width (1.7.0)
|
|
89
|
-
zeitwerk (2.4.
|
|
91
|
+
zeitwerk (2.4.1)
|
|
90
92
|
|
|
91
93
|
PLATFORMS
|
|
92
94
|
ruby
|
|
93
95
|
|
|
94
96
|
DEPENDENCIES
|
|
95
|
-
armitage-rubocop (~>
|
|
97
|
+
armitage-rubocop (~> 1.2)
|
|
96
98
|
bundler (~> 2.1)
|
|
97
99
|
pry (~> 0.13)
|
|
98
100
|
rake (~> 13.0)
|
|
99
|
-
rspec (~> 3.
|
|
101
|
+
rspec (~> 3.10)
|
|
100
102
|
simplecov (~> 0.19)
|
|
101
103
|
smart_schema!
|
|
102
104
|
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SmartCore::Schema [](https://badge.fury.io/rb/smart_schema) [](https://travis-ci.org/smart-rb/smart_schema)
|
|
2
2
|
|
|
3
|
-
`SmartCore::Schema` is a schema validator for `Hash`-like data structures.
|
|
3
|
+
`SmartCore::Schema` is a schema validator for `Hash`-like data structures in declarative DSL-powered style.
|
|
4
4
|
|
|
5
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
6
|
|
|
@@ -88,7 +88,7 @@ result = MySchema.new.validate(
|
|
|
88
88
|
|
|
89
89
|
# => outputs:
|
|
90
90
|
# #<SmartCore::Schema::Result:0x00007ffcd8926990
|
|
91
|
-
# @errors={"key.data"=>[:non_filled], "key.value"=>[:invalid_type], "key.nested"=>[:required_key_not_found], "another_key"=>[:non_filled]},
|
|
91
|
+
# @errors={"key.data"=>[:non_filled], "key.value"=>[:invalid_type], "key.nested"=>[:required_key_not_found], "another_key"=>[:non_filled], "third_key"=>[:extra_key]},
|
|
92
92
|
# @extra_keys=#<Set: {"third_key"}>,
|
|
93
93
|
# @source={:key=>{:data=>nil, :value=>"1", :name=>"D@iVeR"}, :another_key=>nil, :third_key=>"test"}>
|
|
94
94
|
|
|
@@ -99,20 +99,28 @@ result.errors # =>
|
|
|
99
99
|
"key.data"=>[:non_filled],
|
|
100
100
|
"key.value"=>[:invalid_type],
|
|
101
101
|
"key.nested"=>[:required_key_not_found],
|
|
102
|
-
"another_key"=>[:non_filled]
|
|
102
|
+
"another_key"=>[:non_filled],
|
|
103
|
+
"third_key"=>[:extra_key]
|
|
103
104
|
}
|
|
104
105
|
```
|
|
105
106
|
|
|
107
|
+
Possible errors:
|
|
108
|
+
- `:non_filled` (existing key has nil value);
|
|
109
|
+
- `:invalid_type` (existing key has invalid type);
|
|
110
|
+
- `:required_key_not_found` (required key does not exist);
|
|
111
|
+
- `:extra_key` (a key that does not exist in schema);
|
|
112
|
+
|
|
106
113
|
---
|
|
107
114
|
|
|
108
115
|
## Roadmap
|
|
109
116
|
|
|
110
|
-
- **(0.
|
|
117
|
+
- **(0.3.0)** - schema inheritance;
|
|
111
118
|
- **(0.3.0)** - schema composition (`required(:key).schema(SchemaClass)`) (`compose_with(AnotherSchema)`);
|
|
112
|
-
- **(0.4.0)** -
|
|
113
|
-
- **(0.5.0)** -
|
|
114
|
-
- **(0.6.0)** -
|
|
115
|
-
- **(0.7.0)** -
|
|
119
|
+
- **(0.4.0)** - dependable schema checking (sample: if one key exist (or not) we should check another (or not), and vice verca);
|
|
120
|
+
- **(0.5.0)** - error messages (that are consistent with error codes);
|
|
121
|
+
- **(0.6.0)** - `smart_type-system` integration;
|
|
122
|
+
- **(0.7.0)** - support for another data structures (such as YAML strings, JSON strings, `Struct`, `OpenStruct`s, custom `Object`s and etc);
|
|
123
|
+
- **(0.8.0)** - think about pattern matching;
|
|
116
124
|
|
|
117
125
|
---
|
|
118
126
|
|
|
@@ -7,7 +7,7 @@ module SmartCore::Schema::Checker::Reconciler::Matcher::ResultFinalizer
|
|
|
7
7
|
#
|
|
8
8
|
# @api private
|
|
9
9
|
# @since 0.1.0
|
|
10
|
-
ERRORS_CONTAINER_BUILDER = -> { Hash.new { |hash, key| hash[key] =
|
|
10
|
+
ERRORS_CONTAINER_BUILDER = -> { Hash.new { |hash, key| hash[key] = Set.new } }
|
|
11
11
|
|
|
12
12
|
# @return [Proc]
|
|
13
13
|
#
|
|
@@ -15,6 +15,12 @@ module SmartCore::Schema::Checker::Reconciler::Matcher::ResultFinalizer
|
|
|
15
15
|
# @since 0.1.0
|
|
16
16
|
EXTRA_KEYS_CONTAINER_BUILDER = -> { Set.new }
|
|
17
17
|
|
|
18
|
+
# @return [Symbol]
|
|
19
|
+
#
|
|
20
|
+
# @api private
|
|
21
|
+
# @since 0.2.0
|
|
22
|
+
EXTRA_KEY_ERROR_CODE = :extra_key
|
|
23
|
+
|
|
18
24
|
class << self
|
|
19
25
|
# @param result [SmartCore::Schema::Checker::Reconciler::Matcher::Result]
|
|
20
26
|
# @return [SmartCore::Schema::Result]
|
|
@@ -98,10 +104,12 @@ module SmartCore::Schema::Checker::Reconciler::Matcher::ResultFinalizer
|
|
|
98
104
|
|
|
99
105
|
# @param errors [Hash]
|
|
100
106
|
# @param extra_keys [Set]
|
|
101
|
-
# @return [Array<Hash<String,
|
|
107
|
+
# @return [Array<Hash<String,Set<Symbol>>,Set<String>]
|
|
102
108
|
#
|
|
103
109
|
# @api private
|
|
104
110
|
# @since 0.1.0
|
|
111
|
+
# @version 0.2.0
|
|
112
|
+
# rubocop:disable Metrics/AbcSize
|
|
105
113
|
def compile_errors(errors, extra_keys, initial_error_key = nil)
|
|
106
114
|
compiled_errors = ERRORS_CONTAINER_BUILDER.call
|
|
107
115
|
compiled_extra_keys = EXTRA_KEYS_CONTAINER_BUILDER.call
|
|
@@ -130,7 +138,12 @@ module SmartCore::Schema::Checker::Reconciler::Matcher::ResultFinalizer
|
|
|
130
138
|
end
|
|
131
139
|
end
|
|
132
140
|
|
|
141
|
+
compiled_extra_keys.each do |compiled_extra_key|
|
|
142
|
+
compiled_errors[compiled_extra_key] << EXTRA_KEY_ERROR_CODE
|
|
143
|
+
end
|
|
144
|
+
|
|
133
145
|
[compiled_errors, compiled_extra_keys]
|
|
134
146
|
end
|
|
147
|
+
# rubocop:enable Metrics/AbcSize
|
|
135
148
|
end
|
|
136
149
|
end
|
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
# @since 0.1.0
|
|
5
5
|
class SmartCore::Schema::Checker::Rules
|
|
6
6
|
# @todo rework with smart_type-system
|
|
7
|
+
# @note non-frized constant is used for temporary extendability
|
|
7
8
|
# @return [SmartCore::Types::Primitive]
|
|
8
9
|
#
|
|
9
10
|
# @api private
|
|
10
11
|
# @since 0.1.0
|
|
12
|
+
# @version 0.2.0
|
|
13
|
+
# rubocop:disable Style/MutableConstant
|
|
11
14
|
TYPE_ALIASES = {
|
|
12
15
|
'value.any' => SmartCore::Types::Value::Any.nilable,
|
|
13
16
|
'value.nil' => SmartCore::Types::Value::Nil.nilable,
|
|
@@ -47,5 +50,6 @@ class SmartCore::Schema::Checker::Rules
|
|
|
47
50
|
'date_time' => SmartCore::Types::Value::DateTime.nilable,
|
|
48
51
|
'date' => SmartCore::Types::Value::Date.nilable,
|
|
49
52
|
'time_based' => SmartCore::Types::Value::TimeBased.nilable
|
|
50
|
-
}
|
|
53
|
+
}
|
|
54
|
+
# rubocop:enable Style/MutableConstant
|
|
51
55
|
end
|
data/smart_schema.gemspec
CHANGED
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
|
34
34
|
spec.add_development_dependency 'pry', '~> 0.13'
|
|
35
35
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
|
36
36
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
37
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
|
38
|
-
spec.add_development_dependency 'armitage-rubocop', '~>
|
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
|
38
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 1.2'
|
|
39
39
|
spec.add_development_dependency 'simplecov', '~> 0.19'
|
|
40
40
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_schema
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rustam Ibragimov
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: smart_engine
|
|
@@ -86,28 +86,28 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '3.
|
|
89
|
+
version: '3.10'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '3.
|
|
96
|
+
version: '3.10'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: armitage-rubocop
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
101
|
- - "~>"
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '
|
|
103
|
+
version: '1.2'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '
|
|
110
|
+
version: '1.2'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: simplecov
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -185,7 +185,7 @@ metadata:
|
|
|
185
185
|
homepage_uri: https://github.com/smart-rb/smart_schema
|
|
186
186
|
source_code_uri: https://github.com/smart-rb/smart_schema
|
|
187
187
|
changelog_uri: https://github.com/smart-rb/smart_schema/blob/master/CHANGELOG.md
|
|
188
|
-
post_install_message:
|
|
188
|
+
post_install_message:
|
|
189
189
|
rdoc_options: []
|
|
190
190
|
require_paths:
|
|
191
191
|
- lib
|
|
@@ -200,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
200
200
|
- !ruby/object:Gem::Version
|
|
201
201
|
version: '0'
|
|
202
202
|
requirements: []
|
|
203
|
-
rubygems_version: 3.1.
|
|
204
|
-
signing_key:
|
|
203
|
+
rubygems_version: 3.1.4
|
|
204
|
+
signing_key:
|
|
205
205
|
specification_version: 4
|
|
206
206
|
summary: SmartCore::Schema is a schema validator for Hash-like data structures
|
|
207
207
|
test_files: []
|