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.



67
68
69
70
# File 'lib/dry/validation/executor.rb', line 67

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

Instance Attribute Details

#finalObject (readonly)

Returns the value of attribute final.



61
62
63
# File 'lib/dry/validation/executor.rb', line 61

def final
  @final
end

#stepsObject (readonly)

Returns the value of attribute steps.



61
62
63
# File 'lib/dry/validation/executor.rb', line 61

def steps
  @steps
end

Class Method Details

.new(&block) ⇒ Object



63
64
65
# File 'lib/dry/validation/executor.rb', line 63

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

Instance Method Details

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



72
73
74
75
76
77
78
# File 'lib/dry/validation/executor.rb', line 72

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