Class: Simplerubysteps::State

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

Direct Known Subclasses

Callback, Choice, Parallel, Task, Wait

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ State

Returns a new instance of State.



79
80
81
82
# File 'lib/simplerubysteps/model.rb', line 79

def initialize(name)
  @name = name
  @dict = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



76
77
78
# File 'lib/simplerubysteps/model.rb', line 76

def name
  @name
end

#state_machineObject

Returns the value of attribute state_machine.



77
78
79
# File 'lib/simplerubysteps/model.rb', line 77

def state_machine
  @state_machine
end

Instance Method Details

#[]=(key, value) ⇒ Object



84
85
86
# File 'lib/simplerubysteps/model.rb', line 84

def []=(key, value)
  @dict[key] = value
end

#error_catch(state, error = "States.ALL") ⇒ Object

 FIXME move to new baseclass for Task and Callback



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/simplerubysteps/model.rb', line 121

def error_catch(state, error = "States.ALL") # FIXME move to new baseclass for Task and Callback
  data = {
    :ErrorEquals => [error],
    :Next => (state.is_a? Symbol) ? state : state.name,
    :ResultPath => "$.error",
  }

  unless @dict[:Catch]
    @dict[:Catch] = [data]
  else
    @dict[:Catch].push data
  end
end

#error_retry(interval, max, backoff, error = "States.ALL") ⇒ Object

 FIXME move to new baseclass for Task and Callback



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/simplerubysteps/model.rb', line 98

def error_retry(interval, max, backoff, error = "States.ALL") # FIXME move to new baseclass for Task and Callback
  data = {
    :ErrorEquals => [error],
    :IntervalSeconds => interval,
    :BackoffRate => backoff,
    :MaxAttempts => max,
  }

  unless @dict[:Retry]
    @dict[:Retry] = [data]
  else
    @dict[:Retry].push data
  end
end

#next=(state) ⇒ Object



88
89
90
# File 'lib/simplerubysteps/model.rb', line 88

def next=(state)
  @dict[:Next] = (state.is_a? Symbol) ? state : state.name
end

#renderObject



92
93
94
95
96
# File 'lib/simplerubysteps/model.rb', line 92

def render
  dict = @dict
  dict[:End] = true unless dict[:Next]
  dict
end

#task_timeout(secs, state = nil) ⇒ Object

 FIXME move to new baseclass for Task and Callback



113
114
115
116
117
118
119
# File 'lib/simplerubysteps/model.rb', line 113

def task_timeout(secs, state = nil) # FIXME move to new baseclass for Task and Callback
  @dict[:TimeoutSeconds] = secs

  if state
    error_catch state, "States.Timeout"
  end
end