Class: StatesLanguageMachine::States::Wait

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, state_name) ⇒ Wait

Returns a new instance of Wait.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_slm/states/wait.rb', line 8

def initialize(definition, state_name)
  @state_name = state_name

  # Ensure definition is a Hash and extract values safely
  @state_type = definition.is_a?(Hash) ? definition["Type"] : nil
  @seconds = definition.is_a?(Hash) ? definition["Seconds"] : nil
  @timestamp = definition.is_a?(Hash) ? definition["Timestamp"] : nil
  @seconds_path = definition.is_a?(Hash) ? definition["SecondsPath"] : nil
  @timestamp_path = definition.is_a?(Hash) ? definition["TimestampPath"] : nil
  @next_state = definition.is_a?(Hash) ? definition["Next"] : nil

  # Safely handle End key - check if it exists and is truthy
  if definition.is_a?(Hash)
    @end_state = definition.key?("End") ? !!definition["End"] : false
  else
    @end_state = false
  end

  validate
end

Instance Attribute Details

#end_stateObject (readonly)

Returns the value of attribute end_state.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def end_state
  @end_state
end

#next_stateObject (readonly)

Returns the value of attribute next_state.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def next_state
  @next_state
end

#secondsObject (readonly)

Returns the value of attribute seconds.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def seconds
  @seconds
end

#seconds_pathObject (readonly)

Returns the value of attribute seconds_path.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def seconds_path
  @seconds_path
end

#state_typeObject (readonly)

Returns the value of attribute state_type.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def state_type
  @state_type
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def timestamp
  @timestamp
end

#timestamp_pathObject (readonly)

Returns the value of attribute timestamp_path.



6
7
8
# File 'lib/ruby_slm/states/wait.rb', line 6

def timestamp_path
  @timestamp_path
end

Instance Method Details

#execute(context) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_slm/states/wait.rb', line 29

def execute(context)
  # Determine how long to wait
  wait_seconds = calculate_wait_seconds(context)

  # Perform the wait
  sleep(wait_seconds) if wait_seconds > 0

  # Return execution result
  ExecutionResult.new(
    next_state: @end_state ? nil : @next_state,
    output: context.execution_input,
    end_execution: @end_state
  )
end