FlawlessState::State
Inherits Struct < Value < Object
Constructors
new(transitions = self.defined_states)
transitions are a Hash(Symbol,Array(Symbol) which reprsent
what a state is allowed to transitio to
Instance methods
build_transitions(definitions : Hash(Symbol, Array(Symbol)))
Create the @state_pairs array of tuples. Each tuple is a from_state to a to_state. #defined_states
would produce the following pairs. Each each is an allowed to-> from set of states.
[{:new, :initialized},
{:new, :ready},
{:new, :complete},
{:initialized, :ready},
{:initialized, :complete},
{:ready, :complete}]
current_state
Sourcedefined_states
each key results in an array that can be transitioned into.
see #build_transitions
is?(state : Symbol)
Sourceis_not?(state : Symbol)
Sourcestate_pairs
Sourcestate_pairs=(state_pairs : Array(Tuple(Symbol, Symbol)))
Sourceterminal?(state : Symbol = @current_state)
A state is termimal if it is has no valid states to transition to (empty arrays in #defined_states)
States can be forced to other states with #transition_to!
transition_to(new_state : Symbol)
if a transition is permitted, make it, otherwise raise an exception
transition_to!(new_state : Symbol)
force a transition without checking the validity of the new state