Class: Philiprehberger::StateMachine::ParallelStateSet
- Inherits:
-
Object
- Object
- Philiprehberger::StateMachine::ParallelStateSet
- Defined in:
- lib/philiprehberger/state_machine/parallel_state.rb
Overview
Manages parallel (concurrent) substates that can be active simultaneously.
Instance Attribute Summary collapse
-
#active ⇒ Array<Symbol>
readonly
The active substates.
Instance Method Summary collapse
-
#activate(states) ⇒ Object
Activate a set of parallel substates.
-
#active?(state) ⇒ Boolean
Check if a specific substate is active.
-
#any_active? ⇒ Boolean
Check if any parallel substates are active.
-
#deactivate ⇒ Object
Deactivate all parallel substates.
-
#initialize ⇒ ParallelStateSet
constructor
A new instance of ParallelStateSet.
Constructor Details
#initialize ⇒ ParallelStateSet
Returns a new instance of ParallelStateSet.
10 11 12 |
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 10 def initialize @active = [] end |
Instance Attribute Details
#active ⇒ Array<Symbol> (readonly)
Returns the active substates.
8 9 10 |
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 8 def active @active end |
Instance Method Details
#activate(states) ⇒ Object
Activate a set of parallel substates.
17 18 19 |
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 17 def activate(states) @active = states.dup end |
#active?(state) ⇒ Boolean
Check if a specific substate is active.
30 31 32 |
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 30 def active?(state) @active.include?(state) end |
#any_active? ⇒ Boolean
Check if any parallel substates are active.
37 38 39 |
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 37 def any_active? !@active.empty? end |
#deactivate ⇒ Object
Deactivate all parallel substates.
22 23 24 |
# File 'lib/philiprehberger/state_machine/parallel_state.rb', line 22 def deactivate @active = [] end |