Class: StatesLanguageMachine::States::Succeed

Inherits:
Base show all
Defined in:
lib/ruby_slm/states/succeed.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#comment, #definition

Attributes inherited from StatesLanguageMachine::State

#end_state, #name, #next_state, #type

Instance Method Summary collapse

Methods inherited from StatesLanguageMachine::State

#end_state?, #next_state_name

Constructor Details

#initialize(name, definition) ⇒ Succeed

Returns a new instance of Succeed.

Parameters:

  • name (String)

    the name of the state

  • definition (Hash)

    the state definition



13
14
15
16
17
# File 'lib/ruby_slm/states/succeed.rb', line 13

def initialize(name, definition)
  super
  @input_path = definition["InputPath"]
  @output_path = definition["OutputPath"]
end

Instance Attribute Details

#input_pathString? (readonly)

Returns the input path.

Returns:

  • (String, nil)

    the input path



7
8
9
# File 'lib/ruby_slm/states/succeed.rb', line 7

def input_path
  @input_path
end

#output_pathString? (readonly)

Returns the output path.

Returns:

  • (String, nil)

    the output path



9
10
11
# File 'lib/ruby_slm/states/succeed.rb', line 9

def output_path
  @output_path
end

Instance Method Details

#execute(execution, input) ⇒ Hash

Returns the output data from the state.

Parameters:

  • execution (Execution)

    the current execution

  • input (Hash)

    the input data for the state

Returns:

  • (Hash)

    the output data from the state



22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_slm/states/succeed.rb', line 22

def execute(execution, input)
  execution.logger&.info("Executing succeed state: #{@name}")

  processed_input = apply_input_path(input, @input_path)
  final_output = apply_output_path(processed_input, @output_path)

  execution.status = :succeeded
  process_result(execution, final_output)
  final_output
end

#validate!Object

Validate the succeed state definition



34
35
36
# File 'lib/ruby_slm/states/succeed.rb', line 34

def validate!
  # Succeed states don't need Next or End
end