Class: FlowBase

Inherits:
Object
  • Object
show all
Includes:
Technologic
Defined in:
lib/flow/flow_base.rb

Overview

A flow is a collection of procedurally executed operations sharing a common state.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**input) ⇒ FlowBase

Returns a new instance of FlowBase.



32
33
34
# File 'lib/flow/flow_base.rb', line 32

def initialize(**input)
  @state = state_class.new(**input)
end

Instance Attribute Details

#state ⇒ Object (readonly)

Returns the value of attribute state.



28
29
30
# File 'lib/flow/flow_base.rb', line 28

def state
  @state
end

Class Method Details

.inherited(base) ⇒ Object



22
23
24
25
# File 'lib/flow/flow_base.rb', line 22

def inherited(base)
  base._operations = _operations.dup
  super
end

.operations(*operations) ⇒ Object



18
19
20
# File 'lib/flow/flow_base.rb', line 18

def operations(*operations)
  _operations.concat(operations.flatten)
end

.state_class ⇒ Object



10
11
12
# File 'lib/flow/flow_base.rb', line 10

def state_class
  "#{name.chomp("Flow")}State".constantize
end

.trigger(*arguments) ⇒ Object



14
15
16
# File 'lib/flow/flow_base.rb', line 14

def trigger(*arguments)
  new(*arguments).trigger
end

Instance Method Details

#trigger ⇒ Object



36
37
38
39
40
41
42
# File 'lib/flow/flow_base.rb', line 36

def trigger
  surveil(:trigger) do
    _operations.each { |operation| operation.execute(state) }
  end

  state
end