struct

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

Source

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}]
Source
current_state
Source
defined_states

each key results in an array that can be transitioned into. see #build_transitions

Source
is?(state : Symbol)
Source
is_not?(state : Symbol)
Source
state_pairs
Source
state_pairs=(state_pairs : Array(Tuple(Symbol, Symbol)))
Source
terminal?(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!

Source
transition_to(new_state : Symbol)

if a transition is permitted, make it, otherwise raise an exception

Source
transition_to!(new_state : Symbol)

force a transition without checking the validity of the new state

Source