Class: Dry::Validation::Executor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(final) ⇒ Executor

Returns a new instance of Executor.



91
92
93
94
# File 'lib/dry/validation/executor.rb', line 91

def initialize(final)
  @steps = []
  @final = final
end

Instance Attribute Details

#finalObject (readonly)

Returns the value of attribute final.



85
86
87
# File 'lib/dry/validation/executor.rb', line 85

def final
  @final
end

#stepsObject (readonly)

Returns the value of attribute steps.



85
86
87
# File 'lib/dry/validation/executor.rb', line 85

def steps
  @steps
end

Class Method Details

.new(path, &block) ⇒ Object



87
88
89
# File 'lib/dry/validation/executor.rb', line 87

def self.new(path, &block)
  super(BuildErrors[path]).tap { |executor| yield(executor.steps) }.freeze
end

Instance Method Details

#call(input, result = {}) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/dry/validation/executor.rb', line 96

def call(input, result = {})
  output = steps.reduce(input) do |a, e|
    return [a, final.(result)] if result.key?(nil)
    e.call(a, result)
  end
  [output, final.(result)]
end