lib/dry/validation/rule.rb in dry-validation-1.5.2 vs lib/dry/validation/rule.rb in dry-validation-1.5.3
- old
+ new
@@ -63,12 +63,12 @@
#
# The function will be applied only if schema checks passed
# for a given array item.
#
# @example
- # rule(:nums).each do
- # key.failure("must be greater than 0") if value < 0
+ # rule(:nums).each do |index:|
+ # key([:number, index]).failure("must be greater than 0") if value < 0
# end
# rule(:nums).each(min: 3)
# rule(address: :city) do
# key.failure("oops") if value != 'Munich'
# end
@@ -84,12 +84,12 @@
@block = proc do
unless result.base_error?(root) || !values.key?(root)
values[root].each_with_index do |_, idx|
path = [*Schema::Path[root].to_a, idx]
- next if result.error?(path)
+ next if result.schema_error?(path)
- evaluator = with(macros: macros, keys: [path], &block)
+ evaluator = with(macros: macros, keys: [path], index: idx, &block)
failures.concat(evaluator.failures)
end
end
end