dry-validation 0.5.0 → 0.6.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/.codeclimate.yml +16 -0
- data/CHANGELOG.md +23 -2
- data/Gemfile +1 -0
- data/config/errors.yml +2 -0
- data/dry-validation.gemspec +3 -3
- data/lib/dry/validation/error_compiler.rb +46 -10
- data/lib/dry/validation/hint_compiler.rb +5 -0
- data/lib/dry/validation/result.rb +5 -1
- data/lib/dry/validation/schema.rb +14 -11
- data/lib/dry/validation/schema/attr.rb +37 -0
- data/lib/dry/validation/schema/definition.rb +23 -5
- data/lib/dry/validation/schema/form.rb +16 -0
- data/lib/dry/validation/schema/key.rb +1 -1
- data/lib/dry/validation/schema/result.rb +11 -3
- data/lib/dry/validation/schema/rule.rb +23 -1
- data/lib/dry/validation/version.rb +1 -1
- data/spec/integration/error_compiler_spec.rb +3 -0
- data/spec/integration/injecting_rules_spec.rb +23 -0
- data/spec/integration/rule_groups_spec.rb +59 -0
- data/spec/integration/schema/attrs_spec.rb +38 -0
- data/spec/integration/schema/check_rules_spec.rb +63 -17
- data/spec/integration/schema/default_key_behavior_spec.rb +23 -0
- data/spec/integration/schema/grouped_rules_spec.rb +57 -0
- data/spec/integration/schema_spec.rb +175 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/define_struct.rb +25 -0
- data/spec/unit/hint_compiler_spec.rb +18 -1
- data/spec/unit/input_type_compiler_spec.rb +2 -2
- data/spec/unit/schema/rule_spec.rb +4 -4
- data/spec/unit/schema/value_spec.rb +2 -2
- metadata +29 -5
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module DefineStruct
|
2
|
+
def from_hash(hash = {})
|
3
|
+
values = members.map do |attr|
|
4
|
+
val = hash[attr]
|
5
|
+
val.is_a?(Hash) ? define_struct(*val.keys).from_hash(val) : val
|
6
|
+
end
|
7
|
+
new(*values)
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_struct(*attrs)
|
11
|
+
Struct.new(*attrs) do
|
12
|
+
extend DefineStruct
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def def_struct(*attrs)
|
18
|
+
Struct.new(*attrs) do
|
19
|
+
extend DefineStruct
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def struct_from_hash(hash)
|
24
|
+
def_struct(*hash.keys).from_hash(hash)
|
25
|
+
end
|
@@ -19,6 +19,22 @@ RSpec.describe HintCompiler, '#call' do
|
|
19
19
|
]
|
20
20
|
]
|
21
21
|
]
|
22
|
+
],
|
23
|
+
],
|
24
|
+
[
|
25
|
+
:and, [
|
26
|
+
[:attr, [:height, [:predicate, [:attr?, []]]]],
|
27
|
+
[
|
28
|
+
:or, [
|
29
|
+
[:val, [:height, [:predicate, [:none?, []]]]],
|
30
|
+
[
|
31
|
+
:and, [
|
32
|
+
[:val, [:height, [:predicate, [:int?, []]]]],
|
33
|
+
[:val, [:height, [:predicate, [:gt?, [180]]]]]
|
34
|
+
]
|
35
|
+
]
|
36
|
+
]
|
37
|
+
]
|
22
38
|
]
|
23
39
|
]
|
24
40
|
]
|
@@ -26,7 +42,8 @@ RSpec.describe HintCompiler, '#call' do
|
|
26
42
|
|
27
43
|
it 'returns hint messages for given rules' do
|
28
44
|
expect(compiler.call).to eql(
|
29
|
-
age: ['age must be an integer', 'age must be greater than 18']
|
45
|
+
age: ['age must be an integer', 'age must be greater than 18'],
|
46
|
+
height: ['height must be an integer', 'height must be greater than 180'],
|
30
47
|
)
|
31
48
|
end
|
32
49
|
end
|
@@ -171,7 +171,7 @@ RSpec.describe Dry::Validation::InputTypeCompiler, '#call' do
|
|
171
171
|
expect(input_type['bday' => '2012-01-23 11:07']).to eql(bday: Time.new(2012, 1, 23, 11, 7))
|
172
172
|
end
|
173
173
|
|
174
|
-
it 'supports
|
174
|
+
it 'supports time? => "form.time"' do
|
175
175
|
rule_ast = [
|
176
176
|
[
|
177
177
|
:and,
|
@@ -187,7 +187,7 @@ RSpec.describe Dry::Validation::InputTypeCompiler, '#call' do
|
|
187
187
|
expect(input_type['bday' => '2012-01-23 11:07']).to eql(bday: Time.new(2012, 1, 23, 11, 7))
|
188
188
|
end
|
189
189
|
|
190
|
-
it 'supports
|
190
|
+
it 'supports bool? => "form.bool"' do
|
191
191
|
rule_ast = [
|
192
192
|
[
|
193
193
|
:and,
|
@@ -7,25 +7,25 @@ RSpec.describe Schema::Rule do
|
|
7
7
|
|
8
8
|
describe '#and' do
|
9
9
|
it 'returns a conjunction' do
|
10
|
-
expect(left.and(right)).to match_array([:and, [filled, format]])
|
10
|
+
expect(left.and(right).to_ary).to match_array([:and, [filled, format]])
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#or' do
|
15
15
|
it 'returns a disjunction' do
|
16
|
-
expect(left.or(right)).to match_array([:or, [filled, format]])
|
16
|
+
expect(left.or(right).to_ary).to match_array([:or, [filled, format]])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#xor' do
|
21
21
|
it 'returns an exclusive disjunction' do
|
22
|
-
expect(left.xor(right)).to match_array([:xor, [filled, format]])
|
22
|
+
expect(left.xor(right).to_ary).to match_array([:xor, [filled, format]])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#then' do
|
27
27
|
it 'returns an implication' do
|
28
|
-
expect(left.then(right)).to match_array([:implication, [filled, format]])
|
28
|
+
expect(left.then(right).to_ary).to match_array([:implication, [filled, format]])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe Schema::Value do
|
|
7
7
|
value.key?(:method)
|
8
8
|
end
|
9
9
|
|
10
|
-
expect(rule).to match_array(
|
10
|
+
expect(rule.to_ary).to match_array(
|
11
11
|
[:each, [
|
12
12
|
:payments, [:val, [:payments, [:predicate, [:key?, [:method]]]]]]
|
13
13
|
]
|
@@ -20,7 +20,7 @@ RSpec.describe Schema::Value do
|
|
20
20
|
value.key(:amount) { |amount| amount.float? }
|
21
21
|
end
|
22
22
|
|
23
|
-
expect(rule).to match_array(
|
23
|
+
expect(rule.to_ary).to match_array(
|
24
24
|
[:each, [
|
25
25
|
:payments, [
|
26
26
|
:set, [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Holland
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-01-
|
12
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-configurable
|
@@ -18,6 +18,9 @@ dependencies:
|
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0.1'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.3
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -25,6 +28,9 @@ dependencies:
|
|
25
28
|
- - "~>"
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0.1'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.3
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: dry-container
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +40,7 @@ dependencies:
|
|
34
40
|
version: '0.2'
|
35
41
|
- - ">="
|
36
42
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.2.
|
43
|
+
version: 0.2.8
|
38
44
|
type: :runtime
|
39
45
|
prerelease: false
|
40
46
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +50,7 @@ dependencies:
|
|
44
50
|
version: '0.2'
|
45
51
|
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.
|
53
|
+
version: 0.2.8
|
48
54
|
- !ruby/object:Gem::Dependency
|
49
55
|
name: dry-equalizer
|
50
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +72,9 @@ dependencies:
|
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '0.1'
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.1.2
|
69
78
|
type: :runtime
|
70
79
|
prerelease: false
|
71
80
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -73,6 +82,9 @@ dependencies:
|
|
73
82
|
- - "~>"
|
74
83
|
- !ruby/object:Gem::Version
|
75
84
|
version: '0.1'
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.1.2
|
76
88
|
- !ruby/object:Gem::Dependency
|
77
89
|
name: dry-data
|
78
90
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,6 +155,7 @@ executables: []
|
|
143
155
|
extensions: []
|
144
156
|
extra_rdoc_files: []
|
145
157
|
files:
|
158
|
+
- ".codeclimate.yml"
|
146
159
|
- ".gitignore"
|
147
160
|
- ".rspec"
|
148
161
|
- ".rubocop.yml"
|
@@ -173,6 +186,7 @@ files:
|
|
173
186
|
- lib/dry/validation/messages/yaml.rb
|
174
187
|
- lib/dry/validation/result.rb
|
175
188
|
- lib/dry/validation/schema.rb
|
189
|
+
- lib/dry/validation/schema/attr.rb
|
176
190
|
- lib/dry/validation/schema/definition.rb
|
177
191
|
- lib/dry/validation/schema/form.rb
|
178
192
|
- lib/dry/validation/schema/key.rb
|
@@ -187,18 +201,23 @@ files:
|
|
187
201
|
- spec/integration/custom_predicates_spec.rb
|
188
202
|
- spec/integration/error_compiler_spec.rb
|
189
203
|
- spec/integration/hints_spec.rb
|
204
|
+
- spec/integration/injecting_rules_spec.rb
|
190
205
|
- spec/integration/localized_error_messages_spec.rb
|
191
206
|
- spec/integration/messages/i18n_spec.rb
|
192
207
|
- spec/integration/optional_keys_spec.rb
|
193
208
|
- spec/integration/rule_groups_spec.rb
|
209
|
+
- spec/integration/schema/attrs_spec.rb
|
194
210
|
- spec/integration/schema/check_rules_spec.rb
|
211
|
+
- spec/integration/schema/default_key_behavior_spec.rb
|
195
212
|
- spec/integration/schema/each_with_set_spec.rb
|
213
|
+
- spec/integration/schema/grouped_rules_spec.rb
|
196
214
|
- spec/integration/schema/nested_spec.rb
|
197
215
|
- spec/integration/schema/not_spec.rb
|
198
216
|
- spec/integration/schema/xor_spec.rb
|
199
217
|
- spec/integration/schema_form_spec.rb
|
200
218
|
- spec/integration/schema_spec.rb
|
201
219
|
- spec/spec_helper.rb
|
220
|
+
- spec/support/define_struct.rb
|
202
221
|
- spec/unit/error_compiler_spec.rb
|
203
222
|
- spec/unit/hint_compiler_spec.rb
|
204
223
|
- spec/unit/input_type_compiler_spec.rb
|
@@ -225,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
244
|
version: '0'
|
226
245
|
requirements: []
|
227
246
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.
|
247
|
+
rubygems_version: 2.5.1
|
229
248
|
signing_key:
|
230
249
|
specification_version: 4
|
231
250
|
summary: A simple validation library
|
@@ -236,18 +255,23 @@ test_files:
|
|
236
255
|
- spec/integration/custom_predicates_spec.rb
|
237
256
|
- spec/integration/error_compiler_spec.rb
|
238
257
|
- spec/integration/hints_spec.rb
|
258
|
+
- spec/integration/injecting_rules_spec.rb
|
239
259
|
- spec/integration/localized_error_messages_spec.rb
|
240
260
|
- spec/integration/messages/i18n_spec.rb
|
241
261
|
- spec/integration/optional_keys_spec.rb
|
242
262
|
- spec/integration/rule_groups_spec.rb
|
263
|
+
- spec/integration/schema/attrs_spec.rb
|
243
264
|
- spec/integration/schema/check_rules_spec.rb
|
265
|
+
- spec/integration/schema/default_key_behavior_spec.rb
|
244
266
|
- spec/integration/schema/each_with_set_spec.rb
|
267
|
+
- spec/integration/schema/grouped_rules_spec.rb
|
245
268
|
- spec/integration/schema/nested_spec.rb
|
246
269
|
- spec/integration/schema/not_spec.rb
|
247
270
|
- spec/integration/schema/xor_spec.rb
|
248
271
|
- spec/integration/schema_form_spec.rb
|
249
272
|
- spec/integration/schema_spec.rb
|
250
273
|
- spec/spec_helper.rb
|
274
|
+
- spec/support/define_struct.rb
|
251
275
|
- spec/unit/error_compiler_spec.rb
|
252
276
|
- spec/unit/hint_compiler_spec.rb
|
253
277
|
- spec/unit/input_type_compiler_spec.rb
|