Module: Zen::Service::Plugins::Executable

Extended by:
Plugin
Defined in:
lib/zen/service/plugins/executable.rb

Defined Under Namespace

Modules: ClassMethods Classes: State

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

config, default_options, extended, register_as, service_extension

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



56
57
58
# File 'lib/zen/service/plugins/executable.rb', line 56

def state
  @state
end

Class Method Details

.used(service_class) ⇒ Object



51
52
53
54
# File 'lib/zen/service/plugins/executable.rb', line 51

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



66
67
68
69
70
71
72
73
# File 'lib/zen/service/plugins/executable.rb', line 66

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)


75
76
77
# File 'lib/zen/service/plugins/executable.rb', line 75

def executed?
  state.executed
end

#failure?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/zen/service/plugins/executable.rb', line 149

def failure?
  !success?
end

#initializeObject



58
59
60
# File 'lib/zen/service/plugins/executable.rb', line 58

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

#initialize_cloneObject



62
63
64
# File 'lib/zen/service/plugins/executable.rb', line 62

def initialize_clone(*)
  clear_execution_state!
end

#resultObject



128
129
130
131
132
# File 'lib/zen/service/plugins/executable.rb', line 128

def result
  return state.result unless block_given?

  result_with(yield)
end

#success?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/zen/service/plugins/executable.rb', line 145

def success?
  state.success == true
end

#~@Object



79
80
81
# File 'lib/zen/service/plugins/executable.rb', line 79

def ~@
  state
end