Class: StatesLanguageMachine::States::Base

Inherits:
StatesLanguageMachine::State show all
Defined in:
lib/ruby_slm/states/base.rb

Direct Known Subclasses

Choice, Fail, Parallel, Pass, Succeed, Task

Instance Attribute Summary collapse

Attributes inherited from StatesLanguageMachine::State

#end_state, #name, #next_state, #type

Instance Method Summary collapse

Methods inherited from StatesLanguageMachine::State

#end_state?, #execute, #next_state_name

Constructor Details

#initialize(name, definition) ⇒ Base

Returns a new instance of Base.

Parameters:

  • name (String)

    the name of the state

  • definition (Hash)

    the state definition



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

def initialize(name, definition)
  super(name, definition)
  @comment = definition["Comment"]
  @definition = definition
end

Instance Attribute Details

#commentString? (readonly)

Returns the comment describing the state.

Returns:

  • (String, nil)

    the comment describing the state



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

def comment
  @comment
end

#definitionHash (readonly)

Returns the raw state definition.

Returns:

  • (Hash)

    the raw state definition



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

def definition
  @definition
end

Instance Method Details

#validate!Object

Validate the state definition

Raises:



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

def validate!
  # Base validation - can be overridden by subclasses
  if @end_state && @next_state
    raise DefinitionError, "State '#{@name}' cannot have both End and Next"
  end

  unless @end_state || @next_state
    raise DefinitionError, "State '#{@name}' must have either End or Next"
  end
end