Class: Dry::Validation::ApplyChecks

Inherits:
ApplyRules show all
Defined in:
lib/dry/validation/executor.rb

Instance Attribute Summary

Attributes inherited from ApplyRules

#rules

Instance Method Summary collapse

Methods inherited from ApplyRules

#initialize

Constructor Details

This class inherits a constructor from Dry::Validation::ApplyRules

Instance Method Details

#call(input, result) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dry/validation/executor.rb', line 45

def call(input, result)
  rules.each_with_object(result) do |(name, checks), hash|
    checks.each do |check|
      check_res = check.is_a?(Guard) ? check.(input, result) : check.(input)
      if hash.key?(name)
        if hash[name].is_a?(Array)
          hash[name] << check_res
        else
          hash[name] = [hash[name], check_res]
        end
      else
        hash[name] = check_res if check_res
      end
    end
  end
  input
end