module Excom::Plugins::Executable
Attributes
state[R]
Public Class Methods
new(*)
click to toggle source
# File lib/excom/plugins/executable.rb, line 55 def initialize(*) @state = self.class::State.new(executed: false) end
used(service_class, *)
click to toggle source
# File lib/excom/plugins/executable.rb, line 48 def self.used(service_class, *) service_class.const_set(:State, Class.new(State)) service_class.add_execution_prop(:executed, :success, :result) end
Public Instance Methods
execute(*, &block)
click to toggle source
# File lib/excom/plugins/executable.rb, line 63 def execute(*, &block) clear_execution_state! result = execute!(&block) result_with(result) unless state.has_result? state.executed = true self end
executed?()
click to toggle source
# File lib/excom/plugins/executable.rb, line 72 def executed? state.executed end
failure?()
click to toggle source
# File lib/excom/plugins/executable.rb, line 148 def failure? !success? end
initialize_clone(*)
click to toggle source
# File lib/excom/plugins/executable.rb, line 59 def initialize_clone(*) clear_execution_state! end
result() { || ... }
click to toggle source
# File lib/excom/plugins/executable.rb, line 125 def result return state.result unless block_given? result_with(yield) end
success?()
click to toggle source
# File lib/excom/plugins/executable.rb, line 144 def success? state.success == true end
Private Instance Methods
assign_failed_result(value)
click to toggle source
# File lib/excom/plugins/executable.rb, line 121 def assign_failed_result(value) state.result = value end
assign_failed_state()
click to toggle source
# File lib/excom/plugins/executable.rb, line 112 def assign_failed_state state.success = false state.result = nil end
assign_successful_result(value)
click to toggle source
# File lib/excom/plugins/executable.rb, line 117 def assign_successful_result(value) state.result = value end
assign_successful_state()
click to toggle source
# File lib/excom/plugins/executable.rb, line 107 def assign_successful_state state.success = true state.result = nil end
clear_execution_state!()
click to toggle source
# File lib/excom/plugins/executable.rb, line 84 def clear_execution_state! state.clear! state.executed = false end
execute!()
click to toggle source
# File lib/excom/plugins/executable.rb, line 80 def execute! success! end
failure() { || ... }
click to toggle source
# File lib/excom/plugins/executable.rb, line 94 def failure assign_failed_state assign_failed_result(yield) end
failure!()
click to toggle source
# File lib/excom/plugins/executable.rb, line 103 def failure! assign_failed_state end
result_with(obj)
click to toggle source
# File lib/excom/plugins/executable.rb, line 131 def result_with(obj) if State === obj return state.replace(obj) end state.success = !!obj if state.success assign_successful_result(obj) else assign_failed_result(obj) end end
success() { || ... }
click to toggle source
# File lib/excom/plugins/executable.rb, line 89 def success assign_successful_state assign_successful_result(yield) end
success!()
click to toggle source
# File lib/excom/plugins/executable.rb, line 99 def success! assign_successful_state end