dry-validation 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -7
- data/lib/dry/validation/contract.rb +2 -2
- data/lib/dry/validation/evaluator.rb +1 -1
- data/lib/dry/validation/result.rb +9 -2
- data/lib/dry/validation/rule.rb +4 -4
- data/lib/dry/validation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 335dfa8db4764cd1c86619371fea202bfeb0c80cf9a84a2069d7fe4c92a1f5af
|
4
|
+
data.tar.gz: 851e5d59e8c4a1c9ce338d5e3fb01b02159da120fb2a775bcec5168ac705c20e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da1b675edac12c4d7256cb15b770a87387ffc352330434db7a82f177c65ce21dcc8a4803fce2be1d85d29be8df26979fe6e91d43111cebe04c6875500523c29
|
7
|
+
data.tar.gz: 102cf75e197be20843af749584c2a6abd57ce8334d940bff7dd06dc4e37c54fd451bb244dc3365bca913334e3b0c3b3bd391c68b3f9c4e13c4da6efb9c69213f
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
-
## 1.5.
|
1
|
+
## 1.5.3 2020-07-27
|
2
|
+
|
3
|
+
|
4
|
+
### Added
|
5
|
+
|
6
|
+
- You can now access current value's index via `rule(:foo).each do |index:|` (issue #606 done via #657) (@mrbongiolo)
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
|
10
|
+
- `Result#error?` is now a public API and it takes into consideration both schema and rule errors (issue #655 fixed via #656) (@PragTob)
|
11
|
+
|
12
|
+
[Compare v1.5.2...v1.5.3](https://github.com/dry-rb/dry-validation/compare/v1.5.2...v1.5.3)
|
13
|
+
|
14
|
+
## 1.5.2 2020-07-14
|
2
15
|
|
3
16
|
|
4
17
|
### Fixed
|
5
18
|
|
6
|
-
- dry-monads no longer required for the `:hints` extension (@schokomarie)
|
7
|
-
- Using `full: true` option works as expected with custom rule messages (issue #618 fixed via #651) (@sirfilip)
|
8
|
-
- Using `locale: ...` option works as expected with hints (issue #589 fixed via #652) (@sirfilip)
|
9
19
|
- `key?` predicate in rules no longer crashes when the rule path points to a non-existent array value (issue #653 fixed via #654) (@solnic)
|
10
20
|
|
11
21
|
|
12
|
-
[Compare v1.5.1...v1.5.
|
22
|
+
[Compare v1.5.1...v1.5.2](https://github.com/dry-rb/dry-validation/compare/v1.5.1...v1.5.2)
|
13
23
|
|
14
24
|
## 1.5.1 2020-06-18
|
15
25
|
|
@@ -18,8 +28,7 @@
|
|
18
28
|
|
19
29
|
- dry-monads no longer required for the `:hints` extension (@schokomarie)
|
20
30
|
- Using `full: true` option works as expected with custom rule messages (issue #618 fixed via #651) (@sirfilip)
|
21
|
-
- Using `locale: ...` option works as expected with hints (issue #589 fixed via
|
22
|
-
- `key?` predicate in rules no longer crashes when the rule path points to a non-existent array value (issue #653 fixed via #654) (@solnic)
|
31
|
+
- Using `locale: ...` option works as expected with hints (issue #589 fixed via 652) (@sirfilip)
|
23
32
|
|
24
33
|
|
25
34
|
[Compare v1.5.0...v1.5.1](https://github.com/dry-rb/dry-validation/compare/v1.5.0...v1.5.1)
|
@@ -123,14 +123,14 @@ module Dry
|
|
123
123
|
return path.expand.any? { |nested_path| error?(result, nested_path) }
|
124
124
|
end
|
125
125
|
|
126
|
-
return true if result.
|
126
|
+
return true if result.schema_error?(path)
|
127
127
|
|
128
128
|
path
|
129
129
|
.to_a[0..-2]
|
130
130
|
.any? { |key|
|
131
131
|
curr_path = Schema::Path[path.keys[0..path.keys.index(key)]]
|
132
132
|
|
133
|
-
return false unless result.
|
133
|
+
return false unless result.schema_error?(curr_path)
|
134
134
|
|
135
135
|
result.errors.any? { |err|
|
136
136
|
(other = Schema::Path[err.path]).same_root?(curr_path) && other == curr_path
|
@@ -101,8 +101,15 @@ module Dry
|
|
101
101
|
|
102
102
|
# Check if values include an error for the provided key
|
103
103
|
#
|
104
|
-
# @api
|
104
|
+
# @api public
|
105
105
|
def error?(key)
|
106
|
+
errors.any? { |msg| Schema::Path[msg.path].include?(Schema::Path[key]) }
|
107
|
+
end
|
108
|
+
|
109
|
+
# Check if the base schema (without rules) includes an error for the provided key
|
110
|
+
#
|
111
|
+
# @api private
|
112
|
+
def schema_error?(key)
|
106
113
|
schema_result.error?(key)
|
107
114
|
end
|
108
115
|
|
@@ -116,7 +123,7 @@ module Dry
|
|
116
123
|
key_path = Schema::Path[key]
|
117
124
|
err_path = Schema::Path[error.path]
|
118
125
|
|
119
|
-
|
126
|
+
next unless key_path.same_root?(err_path)
|
120
127
|
|
121
128
|
key_path == err_path
|
122
129
|
}
|
data/lib/dry/validation/rule.rb
CHANGED
@@ -65,8 +65,8 @@ module Dry
|
|
65
65
|
# for a given array item.
|
66
66
|
#
|
67
67
|
# @example
|
68
|
-
# rule(:nums).each do
|
69
|
-
# key.failure("must be greater than 0") if value < 0
|
68
|
+
# rule(:nums).each do |index:|
|
69
|
+
# key([:number, index]).failure("must be greater than 0") if value < 0
|
70
70
|
# end
|
71
71
|
# rule(:nums).each(min: 3)
|
72
72
|
# rule(address: :city) do
|
@@ -86,9 +86,9 @@ module Dry
|
|
86
86
|
values[root].each_with_index do |_, idx|
|
87
87
|
path = [*Schema::Path[root].to_a, idx]
|
88
88
|
|
89
|
-
next if result.
|
89
|
+
next if result.schema_error?(path)
|
90
90
|
|
91
|
-
evaluator = with(macros: macros, keys: [path], &block)
|
91
|
+
evaluator = with(macros: macros, keys: [path], index: idx, &block)
|
92
92
|
|
93
93
|
failures.concat(evaluator.failures)
|
94
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|