struct FSM::State

Overview

Represents a state within the finite state machine.

@property id [String] The unique identifier of the state. @property transitions [Hash(String, Transition)] A collection of transitions associated with the state. @property entry_callbacks [Callable(String, Context)?] Optional callback to be executed when entering the state. @property exit_callbacks [Callable(String, Context)?] Optional callback to be executed when exiting the state.

Defined in:

fsm/state.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.create(id : String) #

Create a new state with the given identifier.

@param id [String] The unique identifier of the state.


[View source]
def self.create(id : String, &) #

Create a new state with the given identifier and execute a block to set up additional configurations.

@param id [String] The unique identifier of the state. @yieldparam self [State] The state instance to be configured.


[View source]

Instance Method Detail

def ==(other : State) #

Compare two states for equality based on their identifiers.

@param other [State] The state to compare with.


[View source]
def all_target_states : Array(String) #

Get a list of all target states reachable through transitions from this state.


[View source]
def id : String #

The unique identifier of the state.


[View source]
def on_entry(&block : String, Context -> ) : self #

Register a new callback to be fired when entering this state.

@yieldparam event [String] The event triggering the entry callback. @yieldparam context [Context] The context associated with the state machine.


[View source]
def on_event(event : String, target : String) : self #

Register a new transition from this state to another state.

@param event [String] The event triggering the transition. @param target [String] The target state after the transition.


[View source]
def on_event(event : String, target : String, &) : self #

Register a new transition with a callback to be executed when the transition is made.

@param event [String] The event triggering the transition. @param target [String] The target state after the transition. @yieldparam event [String] The event triggering the transition. @yieldparam context [Context] The context associated with the state machine.


[View source]
def on_exit(&block : String, Context -> ) : self #

Register new callbacks to be fired when exiting this state.

@yieldparam event [String] The event triggering the exit callbacks. @yieldparam context [Context] The context associated with the state machine.


[View source]