dry-validation 0.3.1 → 0.4.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 +16 -0
- data/README.md +35 -499
- data/lib/dry/validation/error_compiler.rb +9 -4
- data/lib/dry/validation/hint_compiler.rb +69 -0
- data/lib/dry/validation/predicate.rb +0 -4
- data/lib/dry/validation/result.rb +8 -0
- data/lib/dry/validation/rule.rb +44 -0
- data/lib/dry/validation/rule/check.rb +15 -0
- data/lib/dry/validation/rule/composite.rb +20 -7
- data/lib/dry/validation/rule/result.rb +46 -0
- data/lib/dry/validation/rule_compiler.rb +14 -0
- data/lib/dry/validation/schema.rb +33 -3
- data/lib/dry/validation/schema/definition.rb +25 -4
- data/lib/dry/validation/schema/key.rb +8 -8
- data/lib/dry/validation/schema/result.rb +15 -2
- data/lib/dry/validation/schema/rule.rb +32 -5
- data/lib/dry/validation/schema/value.rb +15 -6
- data/lib/dry/validation/version.rb +1 -1
- data/spec/integration/custom_error_messages_spec.rb +1 -1
- data/spec/integration/error_compiler_spec.rb +30 -56
- data/spec/integration/hints_spec.rb +39 -0
- data/spec/integration/localized_error_messages_spec.rb +2 -2
- data/spec/integration/schema/check_rules_spec.rb +28 -0
- data/spec/integration/schema/each_with_set_spec.rb +71 -0
- data/spec/integration/schema/nested_spec.rb +31 -0
- data/spec/integration/schema/not_spec.rb +34 -0
- data/spec/integration/schema/xor_spec.rb +32 -0
- data/spec/integration/schema_form_spec.rb +2 -2
- data/spec/integration/schema_spec.rb +1 -1
- data/spec/shared/predicates.rb +2 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/hint_compiler_spec.rb +32 -0
- data/spec/unit/predicate_spec.rb +0 -10
- data/spec/unit/rule/check_spec.rb +29 -0
- data/spec/unit/rule_compiler_spec.rb +44 -7
- data/spec/unit/schema/rule_spec.rb +31 -0
- data/spec/unit/schema/value_spec.rb +84 -0
- metadata +24 -2
@@ -0,0 +1,31 @@
|
|
1
|
+
RSpec.describe Schema::Rule do
|
2
|
+
let(:filled) { [:val, [:email, [:predicate, [:filled?, []]]]] }
|
3
|
+
let(:format) { [:val, [:email, [:predicate, [:format?, [/regex/]]]]] }
|
4
|
+
|
5
|
+
let(:left) { Schema::Rule.new(:email, filled) }
|
6
|
+
let(:right) { Schema::Rule.new(:email, format) }
|
7
|
+
|
8
|
+
describe '#and' do
|
9
|
+
it 'returns a conjunction' do
|
10
|
+
expect(left.and(right)).to match_array([:and, [filled, format]])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#or' do
|
15
|
+
it 'returns a disjunction' do
|
16
|
+
expect(left.or(right)).to match_array([:or, [filled, format]])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#xor' do
|
21
|
+
it 'returns an exclusive disjunction' do
|
22
|
+
expect(left.xor(right)).to match_array([:xor, [filled, format]])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#then' do
|
27
|
+
it 'returns an implication' do
|
28
|
+
expect(left.then(right)).to match_array([:implication, [filled, format]])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
RSpec.describe Schema::Value do
|
2
|
+
describe '#each' do
|
3
|
+
subject(:value) { Schema::Value.new(:payments) }
|
4
|
+
|
5
|
+
it 'creates an each rule with another rule returned from the block' do
|
6
|
+
rule = value.each do
|
7
|
+
value.key?(:method)
|
8
|
+
end
|
9
|
+
|
10
|
+
expect(rule).to match_array(
|
11
|
+
[:each, [
|
12
|
+
:payments, [:val, [:payments, [:predicate, [:key?, [:method]]]]]]
|
13
|
+
]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'creates an each rule with other rules returned from the block' do
|
18
|
+
rule = value.each do
|
19
|
+
value.key(:method) { |method| method.str? }
|
20
|
+
value.key(:amount) { |amount| amount.float? }
|
21
|
+
end
|
22
|
+
|
23
|
+
expect(rule).to match_array(
|
24
|
+
[:each, [
|
25
|
+
:payments, [
|
26
|
+
:set, [
|
27
|
+
:payments, [
|
28
|
+
[:and, [
|
29
|
+
[:key, [:method, [:predicate, [:key?, []]]]],
|
30
|
+
[:val, [:method, [:predicate, [:str?, []]]]]
|
31
|
+
]],
|
32
|
+
[:and, [
|
33
|
+
[:key, [:amount, [:predicate, [:key?, []]]]],
|
34
|
+
[:val, [:amount, [:predicate, [:float?, []]]]]
|
35
|
+
]],
|
36
|
+
]
|
37
|
+
]
|
38
|
+
]
|
39
|
+
]]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#rule' do
|
45
|
+
subject(:pills) { Schema::Value.new(:pills) }
|
46
|
+
|
47
|
+
it 'appends new check rule' do
|
48
|
+
pills.key(:red, &:filled?)
|
49
|
+
pills.key(:blue, &:filled?)
|
50
|
+
|
51
|
+
pills.rule(:destiny) { pills.rule(:red) | pills.rule(:blue) }
|
52
|
+
|
53
|
+
expect(pills.checks.map(&:to_ary)).to match_array([
|
54
|
+
[
|
55
|
+
:check, [
|
56
|
+
:destiny, [
|
57
|
+
:or, [
|
58
|
+
[:check, [:red, [:predicate, [:red, []]]]],
|
59
|
+
[:check, [:blue, [:predicate, [:blue, []]]]]
|
60
|
+
]
|
61
|
+
]
|
62
|
+
]
|
63
|
+
]
|
64
|
+
])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#not' do
|
69
|
+
subject(:user) { Schema::Value.new(:user) }
|
70
|
+
|
71
|
+
it 'builds a negated rule' do
|
72
|
+
not_email = user.key(:email, &:str?).first.not
|
73
|
+
|
74
|
+
expect(not_email.to_ary).to eql([
|
75
|
+
:not, [
|
76
|
+
:and, [
|
77
|
+
[:key, [:email, [:predicate, [:key?, []]]]],
|
78
|
+
[:val, [:email, [:predicate, [:str?, []]]]]
|
79
|
+
]
|
80
|
+
]
|
81
|
+
])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
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.4.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: 2015-12-
|
12
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dry-configurable
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/dry/validation.rb
|
151
151
|
- lib/dry/validation/error.rb
|
152
152
|
- lib/dry/validation/error_compiler.rb
|
153
|
+
- lib/dry/validation/hint_compiler.rb
|
153
154
|
- lib/dry/validation/input_type_compiler.rb
|
154
155
|
- lib/dry/validation/messages.rb
|
155
156
|
- lib/dry/validation/messages/abstract.rb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/dry/validation/predicates.rb
|
162
163
|
- lib/dry/validation/result.rb
|
163
164
|
- lib/dry/validation/rule.rb
|
165
|
+
- lib/dry/validation/rule/check.rb
|
164
166
|
- lib/dry/validation/rule/composite.rb
|
165
167
|
- lib/dry/validation/rule/each.rb
|
166
168
|
- lib/dry/validation/rule/group.rb
|
@@ -183,15 +185,22 @@ files:
|
|
183
185
|
- spec/integration/custom_error_messages_spec.rb
|
184
186
|
- spec/integration/custom_predicates_spec.rb
|
185
187
|
- spec/integration/error_compiler_spec.rb
|
188
|
+
- spec/integration/hints_spec.rb
|
186
189
|
- spec/integration/localized_error_messages_spec.rb
|
187
190
|
- spec/integration/messages/i18n_spec.rb
|
188
191
|
- spec/integration/optional_keys_spec.rb
|
189
192
|
- spec/integration/rule_groups_spec.rb
|
193
|
+
- spec/integration/schema/check_rules_spec.rb
|
194
|
+
- spec/integration/schema/each_with_set_spec.rb
|
195
|
+
- spec/integration/schema/nested_spec.rb
|
196
|
+
- spec/integration/schema/not_spec.rb
|
197
|
+
- spec/integration/schema/xor_spec.rb
|
190
198
|
- spec/integration/schema_form_spec.rb
|
191
199
|
- spec/integration/schema_spec.rb
|
192
200
|
- spec/shared/predicates.rb
|
193
201
|
- spec/spec_helper.rb
|
194
202
|
- spec/unit/error_compiler_spec.rb
|
203
|
+
- spec/unit/hint_compiler_spec.rb
|
195
204
|
- spec/unit/input_type_compiler_spec.rb
|
196
205
|
- spec/unit/predicate_spec.rb
|
197
206
|
- spec/unit/predicates/bool_spec.rb
|
@@ -217,6 +226,7 @@ files:
|
|
217
226
|
- spec/unit/predicates/size_spec.rb
|
218
227
|
- spec/unit/predicates/str_spec.rb
|
219
228
|
- spec/unit/predicates/time_spec.rb
|
229
|
+
- spec/unit/rule/check_spec.rb
|
220
230
|
- spec/unit/rule/conjunction_spec.rb
|
221
231
|
- spec/unit/rule/disjunction_spec.rb
|
222
232
|
- spec/unit/rule/each_spec.rb
|
@@ -226,6 +236,8 @@ files:
|
|
226
236
|
- spec/unit/rule/set_spec.rb
|
227
237
|
- spec/unit/rule/value_spec.rb
|
228
238
|
- spec/unit/rule_compiler_spec.rb
|
239
|
+
- spec/unit/schema/rule_spec.rb
|
240
|
+
- spec/unit/schema/value_spec.rb
|
229
241
|
- spec/unit/schema_spec.rb
|
230
242
|
homepage: https://github.com/dryrb/dry-validation
|
231
243
|
licenses:
|
@@ -257,15 +269,22 @@ test_files:
|
|
257
269
|
- spec/integration/custom_error_messages_spec.rb
|
258
270
|
- spec/integration/custom_predicates_spec.rb
|
259
271
|
- spec/integration/error_compiler_spec.rb
|
272
|
+
- spec/integration/hints_spec.rb
|
260
273
|
- spec/integration/localized_error_messages_spec.rb
|
261
274
|
- spec/integration/messages/i18n_spec.rb
|
262
275
|
- spec/integration/optional_keys_spec.rb
|
263
276
|
- spec/integration/rule_groups_spec.rb
|
277
|
+
- spec/integration/schema/check_rules_spec.rb
|
278
|
+
- spec/integration/schema/each_with_set_spec.rb
|
279
|
+
- spec/integration/schema/nested_spec.rb
|
280
|
+
- spec/integration/schema/not_spec.rb
|
281
|
+
- spec/integration/schema/xor_spec.rb
|
264
282
|
- spec/integration/schema_form_spec.rb
|
265
283
|
- spec/integration/schema_spec.rb
|
266
284
|
- spec/shared/predicates.rb
|
267
285
|
- spec/spec_helper.rb
|
268
286
|
- spec/unit/error_compiler_spec.rb
|
287
|
+
- spec/unit/hint_compiler_spec.rb
|
269
288
|
- spec/unit/input_type_compiler_spec.rb
|
270
289
|
- spec/unit/predicate_spec.rb
|
271
290
|
- spec/unit/predicates/bool_spec.rb
|
@@ -291,6 +310,7 @@ test_files:
|
|
291
310
|
- spec/unit/predicates/size_spec.rb
|
292
311
|
- spec/unit/predicates/str_spec.rb
|
293
312
|
- spec/unit/predicates/time_spec.rb
|
313
|
+
- spec/unit/rule/check_spec.rb
|
294
314
|
- spec/unit/rule/conjunction_spec.rb
|
295
315
|
- spec/unit/rule/disjunction_spec.rb
|
296
316
|
- spec/unit/rule/each_spec.rb
|
@@ -300,5 +320,7 @@ test_files:
|
|
300
320
|
- spec/unit/rule/set_spec.rb
|
301
321
|
- spec/unit/rule/value_spec.rb
|
302
322
|
- spec/unit/rule_compiler_spec.rb
|
323
|
+
- spec/unit/schema/rule_spec.rb
|
324
|
+
- spec/unit/schema/value_spec.rb
|
303
325
|
- spec/unit/schema_spec.rb
|
304
326
|
has_rdoc:
|