Module: Excom::Plugins::Executable

Defined in:
lib/excom/plugins/executable.rb

Defined Under Namespace

Modules: ClassMethods Classes: State

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



53
54
55
# File 'lib/excom/plugins/executable.rb', line 53

def state
  @state
end

Class Method Details

.used(service_class) ⇒ Object



48
49
50
51
# 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

Instance Method Details

#execute(&block) ⇒ Object



63
64
65
66
67
68
69
70
# 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?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/excom/plugins/executable.rb', line 72

def executed?
  state.executed
end

#failure?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/excom/plugins/executable.rb', line 148

def failure?
  !success?
end

#initializeObject



55
56
57
# File 'lib/excom/plugins/executable.rb', line 55

def initialize(*)
  @state = self.class::State.new(executed: false)
end

#initialize_cloneObject



59
60
61
# File 'lib/excom/plugins/executable.rb', line 59

def initialize_clone(*)
  clear_execution_state!
end

#resultObject



125
126
127
128
129
# File 'lib/excom/plugins/executable.rb', line 125

def result
  return state.result unless block_given?

  result_with(yield)
end

#success?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/excom/plugins/executable.rb', line 144

def success?
  state.success == true
end

#~@Object



76
77
78
# File 'lib/excom/plugins/executable.rb', line 76

def ~@
  state
end