Class: StatesLanguageMachine::States::Fail
- Inherits:
-
Base
- Object
- StatesLanguageMachine::State
- Base
- StatesLanguageMachine::States::Fail
- Defined in:
- lib/ruby_slm/states/fail.rb
Instance Attribute Summary collapse
-
#cause ⇒ String
readonly
The cause of the failure.
-
#error ⇒ String
readonly
The error type.
Attributes inherited from Base
Attributes inherited from StatesLanguageMachine::State
#end_state, #name, #next_state, #type
Instance Method Summary collapse
-
#end_state? ⇒ Boolean
Fail states are always end states.
-
#execute(execution, input) ⇒ Hash
The output data from the state.
-
#initialize(name, definition) ⇒ Fail
constructor
A new instance of Fail.
-
#next_state_name(input = nil) ⇒ nil
Fail states don’t have next states.
-
#validate! ⇒ Object
Validate the fail state definition.
Constructor Details
#initialize(name, definition) ⇒ Fail
Returns a new instance of Fail.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_slm/states/fail.rb', line 13 def initialize(name, definition) # Don't call super - we need to handle this differently for Fail states @name = name @type = definition["Type"] @cause = definition["Cause"] @error = definition["Error"] @definition = definition @end_state = true # Fail states are always end states @next_state = nil # Fail states never have next states validate! end |
Instance Attribute Details
#cause ⇒ String (readonly)
Returns the cause of the failure.
7 8 9 |
# File 'lib/ruby_slm/states/fail.rb', line 7 def cause @cause end |
#error ⇒ String (readonly)
Returns the error type.
9 10 11 |
# File 'lib/ruby_slm/states/fail.rb', line 9 def error @error end |
Instance Method Details
#end_state? ⇒ Boolean
Fail states are always end states
44 45 46 |
# File 'lib/ruby_slm/states/fail.rb', line 44 def end_state? true end |
#execute(execution, input) ⇒ Hash
Returns the output data from the state.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_slm/states/fail.rb', line 29 def execute(execution, input) execution.logger&.info("Executing fail state: #{@name}") # Set execution status to failed execution.status = :failed execution.error = @error execution.cause = @cause process_result(execution, input) input end |
#next_state_name(input = nil) ⇒ nil
Fail states don’t have next states
50 51 52 |
# File 'lib/ruby_slm/states/fail.rb', line 50 def next_state_name(input = nil) nil end |
#validate! ⇒ Object
Validate the fail state definition
56 57 58 59 |
# File 'lib/ruby_slm/states/fail.rb', line 56 def validate! raise DefinitionError, "Fail state '#{@name}' must have a Cause" unless @cause raise DefinitionError, "Fail state '#{@name}' must have an Error" unless @error end |