lib/dry/validation/rule.rb in dry-validation-1.1.0 vs lib/dry/validation/rule.rb in dry-validation-1.1.1
- old
+ new
@@ -67,21 +67,24 @@
# @example
# rule(:nums).each do
# key.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
#
# @return [Rule]
#
# @api public
def each(*macros, &block)
- root = keys
+ root = keys[0]
macros = parse_macros(*macros)
@keys = []
@block = proc do
- values[root].each_with_index do |_, idx|
- path = [*root, idx]
+ (values[root] || []).each_with_index do |_, idx|
+ path = [*Schema::Path[root].to_a, idx]
next if result.error?(path)
evaluator = with(macros: macros, keys: [path], &block)