Class: StatesLanguageMachine::States::Pass

Inherits:
Base show all
Defined in:
lib/ruby_slm/states/pass.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 Base

#validate!

Methods inherited from StatesLanguageMachine::State

#end_state?, #next_state_name

Constructor Details

#initialize(name, definition) ⇒ Pass

Returns a new instance of Pass.

Parameters:

  • name (String)

    the name of the state

  • definition (Hash)

    the state definition



17
18
19
20
21
22
23
# File 'lib/ruby_slm/states/pass.rb', line 17

def initialize(name, definition)
  super
  @result = definition["Result"]
  @result_path = definition["ResultPath"]
  @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



11
12
13
# File 'lib/ruby_slm/states/pass.rb', line 11

def input_path
  @input_path
end

#output_pathString? (readonly)

Returns the output path.

Returns:

  • (String, nil)

    the output path



13
14
15
# File 'lib/ruby_slm/states/pass.rb', line 13

def output_path
  @output_path
end

#resultObject? (readonly)

Returns the result to pass through.

Returns:

  • (Object, nil)

    the result to pass through



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

def result
  @result
end

#result_pathString? (readonly)

Returns the result path.

Returns:

  • (String, nil)

    the result path



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

def result_path
  @result_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



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby_slm/states/pass.rb', line 28

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

  processed_input = apply_input_path(input, @input_path)

  result = @result || processed_input
  output = apply_result_path(input, result, @result_path)
  final_output = apply_output_path(output, @output_path)

  process_result(execution, final_output)
  final_output
end