class FSM::Transition(T)

Overview

A transition from one state to another on an event.

Transition(T) is a class, not a struct, with the same lifecycle as StateDefinition: the builder creates it, mutates it during build via #on and #guard, and it is read-only forever afterward while shared across every interpreter. Making it a class means the builder mutates one shared object rather than a copy, which is why registering a guard and a callback on the yielded transition takes effect. #event and #target are set at construction and never change; the only mutable surface is #on and #guard, which raise SealedStateError once the machine seals it.

Defined in:

fsm/transition.cr

Instance Method Summary

Instance Method Detail

def event : String #

[View source]
def guard(&block : String, T -> Bool) : self #

Register the guard predicate that must return true for this transition to be selected.


[View source]
def internal : self #

Mark this transition internal. Chainable, so it reads as t.internal.on { ... }. Raises once sealed, like #on and #guard, because the internal flag is definition state and sealing means what you built is what runs.


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

Register the transition callback fired during the transition.


[View source]
def target : String #

[View source]