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.



1951
1952
1953
1954
# File 'lib/warg.rb', line 1951

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

Instance Method Details

#run(order) ⇒ Object



1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
# File 'lib/warg.rb', line 1956

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



1971
1972
1973
# File 'lib/warg.rb', line 1971

def to_s
  "(callback)"
end