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.



77
78
79
80
# File 'lib/dry/validation/executor.rb', line 77

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

Instance Attribute Details

#finalObject (readonly)

Returns the value of attribute final.



71
72
73
# File 'lib/dry/validation/executor.rb', line 71

def final
  @final
end

#stepsObject (readonly)

Returns the value of attribute steps.



71
72
73
# File 'lib/dry/validation/executor.rb', line 71

def steps
  @steps
end

Class Method Details

.new(&block) ⇒ Object



73
74
75
# File 'lib/dry/validation/executor.rb', line 73

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

Instance Method Details

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



82
83
84
85
86
87
88
# File 'lib/dry/validation/executor.rb', line 82

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