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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83395b144bcdc666d13ac3cb100e2a7488ba9caa638067f03beee031964da26a
4
- data.tar.gz: fa5f1480a6bff63238c76ffc6ee8c574ccc113048843d5f79c9fdc216b899d23
3
+ metadata.gz: 335dfa8db4764cd1c86619371fea202bfeb0c80cf9a84a2069d7fe4c92a1f5af
4
+ data.tar.gz: 851e5d59e8c4a1c9ce338d5e3fb01b02159da120fb2a775bcec5168ac705c20e
5
5
  SHA512:
6
- metadata.gz: 7d14bcf252cbf7cd6a2d58f936d65da3e71343388b87924f51f56cd7812fecff33bab17f4193cf354cc76fd7d3bbbd2081e847b0c8b54b466c1781599aeba25b
7
- data.tar.gz: 11d241432260233c0b7f8fe03b69e1a2cd44e0e7fd241a90ba5f3eb65eff4f21e7c8c88e3fa5c903dc65dbbd78de537a03368ba47cf714a295c7da8784286af8
6
+ metadata.gz: 1da1b675edac12c4d7256cb15b770a87387ffc352330434db7a82f177c65ce21dcc8a4803fce2be1d85d29be8df26979fe6e91d43111cebe04c6875500523c29
7
+ data.tar.gz: 102cf75e197be20843af749584c2a6abd57ce8334d940bff7dd06dc4e37c54fd451bb244dc3365bca913334e3b0c3b3bd391c68b3f9c4e13c4da6efb9c69213f
@@ -1,15 +1,25 @@
1
- ## 1.5.1 2020-06-18
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.1](https://github.com/dry-rb/dry-validation/compare/v1.5.1...v1.5.1)
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 #652) (@sirfilip)
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.error?(path)
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.error?(curr_path)
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
@@ -175,7 +175,7 @@ module Dry
175
175
  #
176
176
  # @api public
177
177
  def schema_error?(path)
178
- result.error?(path)
178
+ result.schema_error?(path)
179
179
  end
180
180
 
181
181
  # Check if there are any errors on the current rule
@@ -101,8 +101,15 @@ module Dry
101
101
 
102
102
  # Check if values include an error for the provided key
103
103
  #
104
- # @api private
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
- return false unless key_path.same_root?(err_path)
126
+ next unless key_path.same_root?(err_path)
120
127
 
121
128
  key_path == err_path
122
129
  }
@@ -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.error?(path)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.5.2"
5
+ VERSION = "1.5.3"
6
6
  end
7
7
  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.2
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-14 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby