Class: FlowBase

Inherits:
Object
  • Object
show all
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.



30
31
32
# File 'lib/flow/flow_base.rb', line 30

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

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



26
27
28
# File 'lib/flow/flow_base.rb', line 26

def state
  @state
end

Class Method Details

.inherited(base) ⇒ Object



20
21
22
23
# File 'lib/flow/flow_base.rb', line 20

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

.operations(*operations) ⇒ Object



16
17
18
# File 'lib/flow/flow_base.rb', line 16

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

.state_classObject



8
9
10
# File 'lib/flow/flow_base.rb', line 8

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

.trigger(*arguments) ⇒ Object



12
13
14
# File 'lib/flow/flow_base.rb', line 12

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

Instance Method Details

#triggerObject



34
35
36
37
# File 'lib/flow/flow_base.rb', line 34

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