struct FlawlessState::State

Defined in:

flawless_state.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(transitions = self.defined_states) #

transitions are a Hash(Symbol,Array(Symbol) which reprsent what a state is allowed to transitio to


[View source]

Instance Method Detail

def 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}]

[View source]
def current_state : Symbol #

[View source]
def defined_states #

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


[View source]
def is?(state : Symbol) #

[View source]
def is_not?(state : Symbol) #

[View source]
def state_pairs : Array({Symbol, Symbol}) #

[View source]
def state_pairs=(state_pairs : Array(Tuple(Symbol, Symbol))) #

[View source]
def 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!


[View source]
def transition_to(new_state : Symbol) #

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


[View source]
def transition_to!(new_state : Symbol) #

force a transition without checking the validity of the new state


[View source]