dry-validation 0.10.6 → 0.10.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -27
- data/examples/multiple.rb +27 -0
- data/lib/dry/validation/executor.rb +14 -4
- data/lib/dry/validation/schema.rb +5 -1
- data/lib/dry/validation/schema/class_interface.rb +1 -0
- data/lib/dry/validation/schema_compiler.rb +3 -1
- data/lib/dry/validation/version.rb +1 -1
- data/spec/integration/injecting_rules_spec.rb +8 -0
- data/spec/integration/schema/validate_spec.rb +37 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c541af293c9c16eeda5e2b2e61b7cf197e8256f9
|
4
|
+
data.tar.gz: e908b607bb27514a3468fdac766a1bb6e3fc313e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 253b0c4d98f7ec104a9032956cc7a2354702cef2ad99229526cb67cdca9d593cffcce0f667ec41f5a02000295e720edd2050d86056e306b32c6142b36564d0d8
|
7
|
+
data.tar.gz: ca229c8ea5abaf7a832c94103098dd32b9e091f8e67526e4b75956d8e65b34bd5e9c5cecf2a9500a7ac28e67f9ece6cb3490e7bfac46f30edc17fbd6560c5aa2
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,19 @@
|
|
1
|
+
# v0.10.7 2017-05-15
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* `validate` can now be defined multiple times for the same key (kimquy)
|
6
|
+
* Re-using rules between schemas no longer mutates original rule set (pabloh)
|
7
|
+
|
8
|
+
[Compare v0.10.6...v0.10.7](https://github.com/dry-rb/dry-validation/compare/v0.10.6...v0.10.7)
|
9
|
+
|
1
10
|
# v0.10.6 2017-04-26
|
2
11
|
|
3
12
|
### Fixed
|
4
13
|
|
5
14
|
* Fixes issue with wrong localized error messages when namespaced messages are used (kbredemeier)
|
6
15
|
|
7
|
-
[Compare v0.10.5...v0.10.6](https://github.com/
|
16
|
+
[Compare v0.10.5...v0.10.6](https://github.com/dry-rb/dry-validation/compare/v0.10.5...v0.10.6)
|
8
17
|
|
9
18
|
# v0.10.5 2017-01-12
|
10
19
|
|
@@ -12,7 +21,7 @@
|
|
12
21
|
|
13
22
|
* Warnings under MRI 2.4.0 are gone (koic)
|
14
23
|
|
15
|
-
[Compare v0.10.4...v0.10.5](https://github.com/
|
24
|
+
[Compare v0.10.4...v0.10.5](https://github.com/dry-rb/dry-validation/compare/v0.10.4...v0.10.5)
|
16
25
|
|
17
26
|
# v0.10.4 2016-12-03
|
18
27
|
|
@@ -25,7 +34,7 @@
|
|
25
34
|
|
26
35
|
* `version` file is now required by default (georgemillo)
|
27
36
|
|
28
|
-
[Compare v0.10.3...v0.10.4](https://github.com/
|
37
|
+
[Compare v0.10.3...v0.10.4](https://github.com/dry-rb/dry-validation/compare/v0.10.3...v0.10.4)
|
29
38
|
|
30
39
|
# v0.10.3 2016-09-27
|
31
40
|
|
@@ -33,7 +42,7 @@
|
|
33
42
|
|
34
43
|
* Custom predicates work correctly with `each` macro (solnic)
|
35
44
|
|
36
|
-
[Compare v0.10.2...v0.10.3](https://github.com/
|
45
|
+
[Compare v0.10.2...v0.10.3](https://github.com/dry-rb/dry-validation/compare/v0.10.2...v0.10.3)
|
37
46
|
|
38
47
|
# v0.10.2 2016-09-23
|
39
48
|
|
@@ -41,7 +50,7 @@
|
|
41
50
|
|
42
51
|
* Constrained types + hints work again (solnic)
|
43
52
|
|
44
|
-
[Compare v0.10.1...v0.10.2](https://github.com/
|
53
|
+
[Compare v0.10.1...v0.10.2](https://github.com/dry-rb/dry-validation/compare/v0.10.1...v0.10.2)
|
45
54
|
|
46
55
|
# v0.10.1 2016-09-22
|
47
56
|
|
@@ -49,7 +58,7 @@
|
|
49
58
|
|
50
59
|
* Remove obsolete require of `dry/struct` which is now an optional extension (flash-gordon)
|
51
60
|
|
52
|
-
[Compare v0.10.0...v0.10.1](https://github.com/
|
61
|
+
[Compare v0.10.0...v0.10.1](https://github.com/dry-rb/dry-validation/compare/v0.10.0...v0.10.1)
|
53
62
|
|
54
63
|
# v0.10.0 2016-09-21
|
55
64
|
|
@@ -82,7 +91,7 @@
|
|
82
91
|
* `HintCompiler` is gone as hints are now part of the result AST (solnic)
|
83
92
|
* `maybe` macro creates an implication instead of a disjunction (`not(none?).then(*your-predicates)`) (solnic)
|
84
93
|
|
85
|
-
[Compare v0.9.5...v0.10.0](https://github.com/
|
94
|
+
[Compare v0.9.5...v0.10.0](https://github.com/dry-rb/dry-validation/compare/v0.9.5...v0.10.0)
|
86
95
|
|
87
96
|
# v0.9.5 2016-08-16
|
88
97
|
|
@@ -91,7 +100,7 @@
|
|
91
100
|
* Infering multiple predicates with options works as expected ie `value(:str?, min_size?: 3, max_size?: 6)` (solnic)
|
92
101
|
* Default `locale` configured in `I18n` is now respected by the messages compiler (agustin + cavi21)
|
93
102
|
|
94
|
-
[Compare v0.9.4...v0.9.5](https://github.com/
|
103
|
+
[Compare v0.9.4...v0.9.5](https://github.com/dry-rb/dry-validation/compare/v0.9.4...v0.9.5)
|
95
104
|
|
96
105
|
# v0.9.4 2016-08-11
|
97
106
|
|
@@ -99,7 +108,7 @@
|
|
99
108
|
|
100
109
|
* Error messages for sibling deeply nested schemas are nested correctly (timriley)
|
101
110
|
|
102
|
-
[Compare v0.9.3...v0.9.4](https://github.com/
|
111
|
+
[Compare v0.9.3...v0.9.4](https://github.com/dry-rb/dry-validation/compare/v0.9.3...v0.9.4)
|
103
112
|
|
104
113
|
# v0.9.3 2016-07-22
|
105
114
|
|
@@ -117,7 +126,7 @@
|
|
117
126
|
|
118
127
|
* `#messages` is no longer memoized (solnic)
|
119
128
|
|
120
|
-
[Compare v0.9.2...v0.9.3](https://github.com/
|
129
|
+
[Compare v0.9.2...v0.9.3](https://github.com/dry-rb/dry-validation/compare/v0.9.2...v0.9.3)
|
121
130
|
|
122
131
|
# v0.9.2 2016-07-13
|
123
132
|
|
@@ -126,7 +135,7 @@
|
|
126
135
|
* Constrained types now work with `each` macro (solnic)
|
127
136
|
* Array coercion without member type works now ie `required(:arr).maybe(:array?)` (solnic)
|
128
137
|
|
129
|
-
[Compare v0.9.1...v0.9.2](https://github.com/
|
138
|
+
[Compare v0.9.1...v0.9.2](https://github.com/dry-rb/dry-validation/compare/v0.9.1...v0.9.2)
|
130
139
|
|
131
140
|
# v0.9.1 2016-07-11
|
132
141
|
|
@@ -134,7 +143,7 @@
|
|
134
143
|
|
135
144
|
* `I18n` backend is no longer required and set by default (solnic)
|
136
145
|
|
137
|
-
[Compare v0.9.0...v0.9.1](https://github.com/
|
146
|
+
[Compare v0.9.0...v0.9.1](https://github.com/dry-rb/dry-validation/compare/v0.9.0...v0.9.1)
|
138
147
|
|
139
148
|
# v0.9.0 2016-07-08
|
140
149
|
|
@@ -171,7 +180,7 @@
|
|
171
180
|
* Added `MessageSet` that result objects now use (in 1.0.0 it'll be exposed via public API) (solnic)
|
172
181
|
* We can now distinguish error messages from validation hints via `Message` and `Hint` objects (solnic)
|
173
182
|
|
174
|
-
[Compare v0.8.0...v0.9.0](https://github.com/
|
183
|
+
[Compare v0.8.0...v0.9.0](https://github.com/dry-rb/dry-validation/compare/v0.8.0...v0.9.0)
|
175
184
|
|
176
185
|
# v0.8.0 2016-07-01
|
177
186
|
|
@@ -229,7 +238,7 @@
|
|
229
238
|
* Make pry console optional with IRB as a default (flash-gordon)
|
230
239
|
* Remove wrapping rules in :set nodes (solnic)
|
231
240
|
|
232
|
-
[Compare v0.7.4...v0.8.0](https://github.com/
|
241
|
+
[Compare v0.7.4...v0.8.0](https://github.com/dry-rb/dry-validation/compare/v0.7.4...v0.8.0)
|
233
242
|
|
234
243
|
# v0.7.4 2016-04-06
|
235
244
|
|
@@ -242,7 +251,7 @@
|
|
242
251
|
|
243
252
|
* Depending on deeply nested values in high-level rules works now (solnic)
|
244
253
|
|
245
|
-
[Compare v0.7.3...v0.7.4](https://github.com/
|
254
|
+
[Compare v0.7.3...v0.7.4](https://github.com/dry-rb/dry-validation/compare/v0.7.3...v0.7.4)
|
246
255
|
|
247
256
|
# v0.7.3 2016-03-30
|
248
257
|
|
@@ -261,7 +270,7 @@
|
|
261
270
|
|
262
271
|
* Switch from `thread_safe` to `concurrent` (joevandyk)
|
263
272
|
|
264
|
-
[Compare v0.7.2...v0.7.3](https://github.com/
|
273
|
+
[Compare v0.7.2...v0.7.3](https://github.com/dry-rb/dry-validation/compare/v0.7.2...v0.7.3)
|
265
274
|
|
266
275
|
# v0.7.2 2016-03-28
|
267
276
|
|
@@ -270,7 +279,7 @@
|
|
270
279
|
* Support for nested schemas inside high-level rules (solnic)
|
271
280
|
* `Schema#to_proc` so that you can do `data.each(&schema)` (solnic)
|
272
281
|
|
273
|
-
[Compare v0.7.1...v0.7.2](https://github.com/
|
282
|
+
[Compare v0.7.1...v0.7.2](https://github.com/dry-rb/dry-validation/compare/v0.7.1...v0.7.2)
|
274
283
|
|
275
284
|
# v0.7.1 2016-03-21
|
276
285
|
|
@@ -288,7 +297,7 @@
|
|
288
297
|
|
289
298
|
* Now depends on `dry-logic` >= `0.2.1` (solnic)
|
290
299
|
|
291
|
-
[Compare v0.7.0...v0.7.1](https://github.com/
|
300
|
+
[Compare v0.7.0...v0.7.1](https://github.com/dry-rb/dry-validation/compare/v0.7.0...v0.7.1)
|
292
301
|
|
293
302
|
# v0.7.0 2016-03-16
|
294
303
|
|
@@ -330,7 +339,7 @@
|
|
330
339
|
* Validation hints only include relevant messages (solnic)
|
331
340
|
* `:yaml` messages respect `:locale` option in `Result#messages` (solnic)
|
332
341
|
|
333
|
-
[Compare v0.6.0...v0.7.0](https://github.com/
|
342
|
+
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-validation/compare/v0.6.0...v0.7.0)
|
334
343
|
|
335
344
|
# v0.6.0 2016-01-20
|
336
345
|
|
@@ -351,20 +360,20 @@
|
|
351
360
|
* In `Schema::Form` both `key` and `optional` will apply `filled?` predicate by
|
352
361
|
default when no block is passed (solnic)
|
353
362
|
|
354
|
-
[Compare v0.5.0...v0.6.0](https://github.com/
|
363
|
+
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-validation/compare/v0.5.0...v0.6.0)
|
355
364
|
|
356
365
|
# v0.5.0 2016-01-11
|
357
366
|
|
358
367
|
### Changed
|
359
368
|
|
360
|
-
* Now depends on [dry-logic](https://github.com/
|
369
|
+
* Now depends on [dry-logic](https://github.com/dry-rb/dry-logic) for predicates and rules (solnic)
|
361
370
|
* `dry/validation/schema/form` is now required by default (solnic)
|
362
371
|
|
363
372
|
### Fixed
|
364
373
|
|
365
374
|
* `Schema::Form` uses safe `form.array` and `form.hash` types which fixes #42 (solnic)
|
366
375
|
|
367
|
-
[Compare v0.4.1...v0.5.0](https://github.com/
|
376
|
+
[Compare v0.4.1...v0.5.0](https://github.com/dry-rb/dry-validation/compare/v0.4.1...v0.5.0)
|
368
377
|
|
369
378
|
# v0.4.1 2015-12-27
|
370
379
|
|
@@ -372,7 +381,7 @@
|
|
372
381
|
|
373
382
|
* Support for `each` and type coercion inference in `Schema::Form` (solnic)
|
374
383
|
|
375
|
-
[Compare v0.4.0...v0.4.1](https://github.com/
|
384
|
+
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-validation/compare/v0.4.0...v0.4.1)
|
376
385
|
|
377
386
|
# v0.4.0 2015-12-21
|
378
387
|
|
@@ -388,7 +397,7 @@
|
|
388
397
|
|
389
398
|
* Error messages hash has now consistent structure `rule_name => [msgs_array, input_value]` (solnic)
|
390
399
|
|
391
|
-
[Compare v0.3.1...v0.4.0](https://github.com/
|
400
|
+
[Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-validation/compare/v0.3.1...v0.4.0)
|
392
401
|
|
393
402
|
# v0.3.1 2015-12-08
|
394
403
|
|
@@ -400,7 +409,7 @@
|
|
400
409
|
|
401
410
|
* Error compiler returns an empty hash rather than a nil when there are no errors (solnic)
|
402
411
|
|
403
|
-
[Compare v0.3.0...v0.3.1](https://github.com/
|
412
|
+
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-validation/compare/v0.3.0...v0.3.1)
|
404
413
|
|
405
414
|
# v0.3.0 2015-12-07
|
406
415
|
|
@@ -424,7 +433,7 @@
|
|
424
433
|
errors and messages
|
425
434
|
* `Schema::Result#messages` returns a hash with rule names, messages and input values (solnic)
|
426
435
|
|
427
|
-
[Compare v0.2.0...HEAD](https://github.com/
|
436
|
+
[Compare v0.2.0...HEAD](https://github.com/dry-rb/dry-validation/compare/v0.2.0...HEAD)
|
428
437
|
|
429
438
|
# v0.2.0 2015-11-30
|
430
439
|
|
@@ -447,7 +456,7 @@
|
|
447
456
|
|
448
457
|
* Added missing `and` / `or` interfaces to composite rules (solnic)
|
449
458
|
|
450
|
-
[Compare v0.1.0...HEAD](https://github.com/
|
459
|
+
[Compare v0.1.0...HEAD](https://github.com/dry-rb/dry-validation/compare/v0.1.0...HEAD)
|
451
460
|
|
452
461
|
# v0.1.0 2015-11-25
|
453
462
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'dry-validation'
|
2
|
+
|
3
|
+
schema = Dry::Validation.Schema do
|
4
|
+
configure do
|
5
|
+
def self.messages
|
6
|
+
super.merge(en: {
|
7
|
+
errors: {
|
8
|
+
john_email?: '%{value} is not a john email',
|
9
|
+
example_email?: '%{value} is not a example email'
|
10
|
+
} })
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
required(:email).filled
|
15
|
+
|
16
|
+
validate(example_email?: :email) do |value|
|
17
|
+
value.end_with?('@example.com')
|
18
|
+
end
|
19
|
+
|
20
|
+
validate(john_email?: :email) do |value|
|
21
|
+
value.start_with?('john')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
errors = schema.call(email: 'jane@doe.org').messages
|
26
|
+
|
27
|
+
puts errors.inspect
|
@@ -43,9 +43,19 @@ module Dry
|
|
43
43
|
|
44
44
|
class ApplyChecks < ApplyRules
|
45
45
|
def call(input, result)
|
46
|
-
rules.each_with_object(result) do |(name,
|
47
|
-
|
48
|
-
|
46
|
+
rules.each_with_object(result) do |(name, checks), hash|
|
47
|
+
checks.each do |check|
|
48
|
+
check_res = check.is_a?(Guard) ? check.(input, result) : check.(input)
|
49
|
+
if hash.key?(name)
|
50
|
+
if hash[name].is_a?(Array)
|
51
|
+
hash[name] << check_res
|
52
|
+
else
|
53
|
+
hash[name] = [hash[name], check_res]
|
54
|
+
end
|
55
|
+
else
|
56
|
+
hash[name] = check_res if check_res
|
57
|
+
end
|
58
|
+
end
|
49
59
|
end
|
50
60
|
input
|
51
61
|
end
|
@@ -53,7 +63,7 @@ module Dry
|
|
53
63
|
|
54
64
|
class BuildErrors
|
55
65
|
def call(result)
|
56
|
-
result.values.select(&:failure?)
|
66
|
+
result.values.flatten.compact.select(&:failure?)
|
57
67
|
end
|
58
68
|
end
|
59
69
|
|
@@ -114,7 +114,11 @@ module Dry
|
|
114
114
|
|
115
115
|
def initialize_checks(checks)
|
116
116
|
@checks = checks.each_with_object({}) do |check, result|
|
117
|
-
result
|
117
|
+
if result.key?(check.name)
|
118
|
+
result[check.name] << rule_compiler.visit(check.to_ast)
|
119
|
+
else
|
120
|
+
result[check.name] = [rule_compiler.visit(check.to_ast)]
|
121
|
+
end
|
118
122
|
end
|
119
123
|
end
|
120
124
|
end
|
@@ -41,6 +41,7 @@ module Dry
|
|
41
41
|
|
42
42
|
dsl_ext = config.dsl_extensions
|
43
43
|
|
44
|
+
options = options.merge(rules: options[:rules].dup) if options.key?(:rules)
|
44
45
|
dsl = Schema::Value.new(options.merge(registry: source.registry))
|
45
46
|
dsl_ext.__send__(:extend_object, dsl) if dsl_ext
|
46
47
|
dsl.predicates(options[:predicates]) if options.key?(:predicates)
|
@@ -19,4 +19,12 @@ RSpec.describe 'Schema / Injecting Rules' do
|
|
19
19
|
expect(schema.(login: true, email: nil)).to_not be_success
|
20
20
|
expect(schema.(login: nil, email: 'jane@doe')).to_not be_success
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'keeps the original schema rules intact' do
|
24
|
+
expect(other.class.rules.size).to eq(1)
|
25
|
+
|
26
|
+
schema.(login: true, email: 'jane@doe')
|
27
|
+
|
28
|
+
expect(other.class.rules.size).to eq(1)
|
29
|
+
end
|
22
30
|
end
|
@@ -80,4 +80,41 @@ RSpec.describe Dry::Validation::Schema, 'arbitrary validation blocks' do
|
|
80
80
|
)
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
context 'with more than one validation' do
|
85
|
+
subject(:schema) do
|
86
|
+
Dry::Validation.Schema do
|
87
|
+
configure do
|
88
|
+
option :email_regex, /@/
|
89
|
+
|
90
|
+
def self.messages
|
91
|
+
super.merge(en: {
|
92
|
+
errors: {
|
93
|
+
email?: '%{value} looks like an invalid email',
|
94
|
+
google_email?: '%{value} is not a google email'
|
95
|
+
} })
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
required(:email).filled
|
100
|
+
|
101
|
+
validate(email?: :email) do |value|
|
102
|
+
email_regex.match(value)
|
103
|
+
end
|
104
|
+
|
105
|
+
validate(google_email?: :email) do |value|
|
106
|
+
value.end_with?('@google.com')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns errors message for both validate' do
|
112
|
+
expect(schema.(email: 'jane').messages).to eql(
|
113
|
+
email: [
|
114
|
+
'jane looks like an invalid email',
|
115
|
+
'jane is not a google email'
|
116
|
+
]
|
117
|
+
)
|
118
|
+
end
|
119
|
+
end
|
83
120
|
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.10.
|
4
|
+
version: 0.10.7
|
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: 2017-
|
12
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- examples/each.rb
|
194
194
|
- examples/form.rb
|
195
195
|
- examples/json.rb
|
196
|
+
- examples/multiple.rb
|
196
197
|
- examples/nested.rb
|
197
198
|
- lib/dry-validation.rb
|
198
199
|
- lib/dry/validation.rb
|