class States::Dsl::StateLike

Constants

UNSET

Attributes

context[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/states/dsl/state_like.rb, line 8
def initialize(options={})
  @traits = options[:traits] || []
  @result_path = @output_path = @input_path = UNSET
  @retries = []
  @catches = []
end

Public Instance Methods

activity(name) click to toggle source
# File lib/states/dsl/state_like.rb, line 19
def activity(name)
  resource(context.activity_resource(name))
end
catch_if(options={}, &block) click to toggle source
# File lib/states/dsl/state_like.rb, line 75
def catch_if(options={}, &block)
  katch = Catch.new(context, options)
  if block_given?
    katch.instance_eval(&block)
  end
  @catches << katch
end
choices(&block) click to toggle source
# File lib/states/dsl/state_like.rb, line 49
def choices(&block)
  @choices = Choices.new(@context.naming)
  @choices.instance_eval(&block)
  @choices
end
fail(&block) click to toggle source
# File lib/states/dsl/state_like.rb, line 61
def fail(&block)
  @fail = Fail.new
  @fail.instance_eval(&block)
  @fail
end
function(name) click to toggle source
# File lib/states/dsl/state_like.rb, line 15
def function(name)
  resource(context.function_resource(name))
end
input_path(path) click to toggle source
# File lib/states/dsl/state_like.rb, line 35
def input_path(path)
  @input_path = path
end
next_state(state) click to toggle source
# File lib/states/dsl/state_like.rb, line 39
def next_state(state)
  @next_state = context.naming.ref(state)
end
output_path(path) click to toggle source
# File lib/states/dsl/state_like.rb, line 31
def output_path(path)
  @output_path = path
end
parallel(&block) click to toggle source
# File lib/states/dsl/state_like.rb, line 43
def parallel(&block)
  @parallel = Parallel.new(@context)
  @parallel.instance_eval(&block)
  @parallel
end
resource(arn) click to toggle source
# File lib/states/dsl/state_like.rb, line 23
def resource(arn)
  @resource = arn
end
result_path(path) click to toggle source
# File lib/states/dsl/state_like.rb, line 27
def result_path(path)
  @result_path = path
end
retry_if(*arguments, &block) click to toggle source
# File lib/states/dsl/state_like.rb, line 67
def retry_if(*arguments, &block)
  _retry = Retry.new(*arguments)
  if block_given?
    _retry.instance_eval(&block)
  end
  @retries << _retry
end
serializable_hash() click to toggle source
# File lib/states/dsl/state_like.rb, line 83
def serializable_hash
  j = context.lookup_traits(@traits).reduce({}) { |m, t| m.merge(t.serializable_hash) }
  if @resource
    j["Type"] = "Task"
    j["Resource"] = @resource.to_s

  elsif @parallel
    j["Type"] = "Parallel"
    j.merge!(@parallel.serializable_hash)

  elsif @choices
    j["Type"] = "Choice"
    j.merge!(@choices.serializable_hash)

  elsif @wait
    j["Type"] = "Wait"
    j.merge!(@wait.serializable_hash)

  elsif @fail
    j["Type"] = "Fail"
    j.merge!(@fail.serializable_hash)
  end

  [
    [@result_path, "ResultPath"],
    [@input_path , "InputPath" ],
    [@output_path, "OutputPath"],
  ].each { |(k,v)| j[v] = k if k != UNSET }

  unless @retries.empty?
    j["Retry"] = @retries.map(&:serializable_hash)
  end

  unless @catches.empty?
    j["Catch"] = @catches.map(&:serializable_hash)
  end

  if @next_state
    j["Next"] = @next_state.to_s
  end
  j
end
wait(&block) click to toggle source
# File lib/states/dsl/state_like.rb, line 55
def wait(&block)
  @wait = Wait.new(@context.naming)
  @wait.instance_eval(&block)
  @wait
end