Class: Simplerubysteps::Task

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

Instance Attribute Summary

Attributes inherited from State

#name, #state_machine

Instance Method Summary collapse

Methods inherited from State

#[]=, #next=, #render

Constructor Details

#initialize(name) ⇒ Task

Returns a new instance of Task.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/simplerubysteps/model.rb', line 61

def initialize(name)
  super
  @dict[:Type] = "Task"
  @dict[:Resource] = $FUNCTION_ARN
  @dict[:Parameters] = {
    :Task => name,
    "Input.$" => "$",
  }

  action { |input| input } # default: pass through
end

Instance Method Details

#action(&action_block) ⇒ Object



73
74
75
# File 'lib/simplerubysteps/model.rb', line 73

def action(&action_block)
  @action_block = action_block
end

#implicit_choiceObject



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

def implicit_choice
  unless @implicit_choice
    @implicit_choice = Choice.new("#{name}_choice")
    $sm.add @implicit_choice
    self.next = @implicit_choice
  end
  @implicit_choice
end

#perform_action(input) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/simplerubysteps/model.rb', line 77

def perform_action(input)
  output = nil
  output = @action_block.call(input) if @action_block

  if @implicit_choice
    output = {} unless output
    @implicit_choice.perform_action(output)
  end

  output
end