Class: Warg::Command::Step::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/warg.rb

Defined Under Namespace

Classes: Outcome

Instance Method Summary collapse

Constructor Details

#initialize(last_step, run_object) ⇒ Callback

Returns a new instance of Callback.



2041
2042
2043
2044
# File 'lib/warg.rb', line 2041

def initialize(last_step, run_object)
  @last_step = last_step
  @run_object = run_object
end

Instance Method Details

#run(order) ⇒ Object



2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
# File 'lib/warg.rb', line 2046

def run(order)
  Executor.for(order).new(@last_step.result).run do |last_outcome, result|
    callback_outcome = Outcome.new(last_outcome)

    begin
      # Use `||=` in case `#value` is set in the callback
      callback_outcome.value ||= @run_object.(last_outcome.host, last_outcome.value, callback_outcome)
    rescue => error
      callback_outcome.error = error
    end

    result.update callback_outcome
  end
end

#to_sObject



2061
2062
2063
# File 'lib/warg.rb', line 2061

def to_s
  "(callback)"
end