Module: Simplerubysteps

Defined in:
lib/simplerubysteps.rb,
lib/simplerubysteps/version.rb

Defined Under Namespace

Classes: Callback, Choice, ChoiceItem, State, StateMachine, Task

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#action(&action_block) ⇒ Object



213
214
215
# File 'lib/simplerubysteps.rb', line 213

def action(&action_block)
  $tasks.last.action &action_block
end

#callback(name) ⇒ Object



203
204
205
206
207
208
209
210
211
# File 'lib/simplerubysteps.rb', line 203

def callback(name)
  t = $sm.add Callback.new(name)

  $tasks.last.next = t if $tasks.last

  $tasks.push t
  yield if block_given?
  $tasks.pop
end

#choice(name) ⇒ Object



240
241
242
243
244
245
246
247
248
# File 'lib/simplerubysteps.rb', line 240

def choice(name)
  t = $sm.add Choice.new(name)

  $tasks.last.next = t if $tasks.last

  $tasks.push t
  yield if block_given?
  $tasks.pop
end

#defaultObject



263
264
265
266
267
# File 'lib/simplerubysteps.rb', line 263

def default
  $tasks.push $tasks.last
  yield if block_given?
  $tasks.pop
end

#default_transition_to(state) ⇒ Object



234
235
236
237
238
# File 'lib/simplerubysteps.rb', line 234

def default_transition_to(state)
  choice = $tasks.last.implicit_choice

  choice.default = state
end

#function_nameObject



9
10
11
12
# File 'lib/simplerubysteps.rb', line 9

def function_name
  return "unknown" unless $FUNCTION_ARN =~ /.+\:function\:(.+)/
  $1
end

#string_matches(var, match) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/simplerubysteps.rb', line 250

def string_matches(var, match)
  c = ChoiceItem.new({
    :Variable => var,
    :StringMatches => match,
  })

  $tasks.last.add c

  $tasks.push c
  yield if block_given?
  $tasks.pop
end

#task(name) ⇒ Object



193
194
195
196
197
198
199
200
201
# File 'lib/simplerubysteps.rb', line 193

def task(name)
  t = $sm.add Task.new(name)

  $tasks.last.next = t if $tasks.last

  $tasks.push t
  yield if block_given?
  $tasks.pop
end

#transition(state) ⇒ Object



217
218
219
# File 'lib/simplerubysteps.rb', line 217

def transition(state)
  $tasks.last.next = state
end

#transition_to(state, &condition_block) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/simplerubysteps.rb', line 221

def transition_to(state, &condition_block)
  choice = $tasks.last.implicit_choice

  c = ChoiceItem.new({
    :Variable => "$.#{choice.name}_#{state}",
    :StringMatches => "yes",
  })
  c.next = state
  c.implicit_condition_block = condition_block

  choice.add c
end