Class: StatesLanguageMachine::States::CatchPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_slm/states/task.rb

Overview

Catch policy class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ CatchPolicy

Returns a new instance of CatchPolicy.



485
486
487
488
489
# File 'lib/ruby_slm/states/task.rb', line 485

def initialize(definition)
  @error_equals = Array(definition["ErrorEquals"])
  @next = definition["Next"]
  @result_path = definition["ResultPath"]
end

Instance Attribute Details

#error_equalsObject (readonly)

Returns the value of attribute error_equals.



483
484
485
# File 'lib/ruby_slm/states/task.rb', line 483

def error_equals
  @error_equals
end

#nextObject (readonly)

Returns the value of attribute next.



483
484
485
# File 'lib/ruby_slm/states/task.rb', line 483

def next
  @next
end

#result_pathObject (readonly)

Returns the value of attribute result_path.



483
484
485
# File 'lib/ruby_slm/states/task.rb', line 483

def result_path
  @result_path
end

Instance Method Details

#matches?(error) ⇒ Boolean

Returns:

  • (Boolean)


491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/ruby_slm/states/task.rb', line 491

def matches?(error)
  @error_equals.any? do |error_match|
    case error_match
    when "States.ALL"
      true
    when "States.Timeout"
      error.is_a?(TaskTimeoutError)
    when "States.TaskFailed"
      error.is_a?(StandardError) && !error.is_a?(TaskTimeoutError)
    when "States.Permissions"
      error.is_a?(SecurityError) || error.message.include?("permission")
    else
      error.class.name == error_match || error.message.include?(error_match)
    end
  end
end

#validate!Object



508
509
510
511
512
513
514
515
516
# File 'lib/ruby_slm/states/task.rb', line 508

def validate!
  if @error_equals.empty?
    raise DefinitionError, "Catch policy must specify ErrorEquals"
  end

  unless @next
    raise DefinitionError, "Catch policy must specify Next state"
  end
end