Class: Philiprehberger::StateMachine::Transition
- Inherits:
-
Struct
- Object
- Struct
- Philiprehberger::StateMachine::Transition
- Defined in:
- lib/philiprehberger/state_machine/transition.rb
Overview
Represents a single transition from one or more states to a target state.
Instance Attribute Summary collapse
-
#from ⇒ Symbol+
readonly
source state(s).
-
#guard ⇒ Proc?
readonly
optional guard condition.
-
#to ⇒ Symbol
readonly
target state.
Instance Method Summary collapse
-
#from_states ⇒ Array<Symbol>
Returns all source states as an array.
-
#matches?(current_state) ⇒ Boolean
Check if this transition matches the given current state.
Instance Attribute Details
#from ⇒ Symbol+ (readonly)
source state(s)
10 11 12 |
# File 'lib/philiprehberger/state_machine/transition.rb', line 10 def from @from end |
#guard ⇒ Proc? (readonly)
optional guard condition
10 11 12 |
# File 'lib/philiprehberger/state_machine/transition.rb', line 10 def guard @guard end |
#to ⇒ Symbol (readonly)
target state
10 11 12 |
# File 'lib/philiprehberger/state_machine/transition.rb', line 10 def to @to end |
Instance Method Details
#from_states ⇒ Array<Symbol>
Returns all source states as an array.
26 27 28 |
# File 'lib/philiprehberger/state_machine/transition.rb', line 26 def from_states Array(from) end |
#matches?(current_state) ⇒ Boolean
Check if this transition matches the given current state.
15 16 17 18 19 20 21 |
# File 'lib/philiprehberger/state_machine/transition.rb', line 15 def matches?(current_state) if from.is_a?(Array) from.include?(current_state) else from == current_state end end |