Class: Simplerubysteps::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/simplerubysteps/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStateMachine

Returns a new instance of StateMachine.



21
22
23
24
# File 'lib/simplerubysteps/model.rb', line 21

def initialize()
  @states = {}
  @kind = "STANDARD"
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



19
20
21
# File 'lib/simplerubysteps/model.rb', line 19

def kind
  @kind
end

#start_atObject (readonly)

Returns the value of attribute start_at.



18
19
20
# File 'lib/simplerubysteps/model.rb', line 18

def start_at
  @start_at
end

#statesObject (readonly)

Returns the value of attribute states.



17
18
19
# File 'lib/simplerubysteps/model.rb', line 17

def states
  @states
end

Instance Method Details

#add(state) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/simplerubysteps/model.rb', line 26

def add(state)
  @start_at = state.name unless @start_at

  @states[state.name] = state
  state.state_machine = self

  state
end

#cloudformation_configObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/simplerubysteps/model.rb', line 51

def cloudformation_config
  data = []
  deep_states.each do |name, state|
    if state.is_a? Task or state.is_a? Callback
      data.push({
        env: {
          task: name,
        },
        iam_permissions: state.iam_permissions,
        queue: ((state.is_a? Callback) ? state.queue : nil),
      })
    end
  end
  data
end

#deep_statesObject

FIXME refactoring (fragility): order of returned states must be the same as the order of rendered states (lambda mapping by index)



35
36
37
# File 'lib/simplerubysteps/model.rb', line 35

def deep_states # FIXME refactoring (fragility): order of returned states must be the same as the order of rendered states (lambda mapping by index)
  int_deep_states states
end

#int_deep_states(int_states) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/simplerubysteps/model.rb', line 39

def int_deep_states(int_states)
  result = {}
  int_states.each do |name, state|
    if state.is_a? Parallel
      state.branches.each do |branch|
        result = result.merge int_deep_states(branch.states)
      end
    end
  end
  result.merge int_states
end

#renderObject

FIXME refactoring (fragility): order of rendered states must be the same than order of deep_states (lambda mapping by index)



67
68
69
70
71
72
# File 'lib/simplerubysteps/model.rb', line 67

def render # FIXME refactoring (fragility): order of rendered states must be the same than order of deep_states (lambda mapping by index)
  {
    :StartAt => @start_at,
    :States => @states.map { |name, state| [name, state.render] }.to_h,
  }
end