Class: StateMachine::State
- Inherits:
-
Object
- Object
- StateMachine::State
- Defined in:
- lib/motion-state-machine/state.rb
Defined Under Namespace
Classes: TransitionDefinitionDSL
Instance Attribute Summary collapse
-
#entry_actions ⇒ Array
An array of
Proc
objects called when entering the state. -
#exit_actions ⇒ Array
An array of
Proc
objects called when exiting the state. -
#name ⇒ String
The state’s name.
-
#state_machine ⇒ StateMachine::Base
readonly
The FSM that the state belongs to.
-
#symbol ⇒ Symbol
readonly
The state’s identifying symbol.
-
#transition_map ⇒ Hash
readonly
The state machine’s internal transition map (event types -> event values -> possible transitions).
Instance Method Summary collapse
-
#initialize(state_machine, options) ⇒ StateMachine::State
constructor
Initializes a new State.
-
#register(transition) ⇒ Object
private
Registers a transition in the transition map.
- #terminating=(value) ⇒ Object
-
#terminating? ⇒ Boolean
Indicates if the state is a termination state.
Constructor Details
#initialize(state_machine, options) ⇒ StateMachine::State
Initializes a new State.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/motion-state-machine/state.rb', line 59 def initialize(state_machine, ) @state_machine = state_machine @symbol = [:symbol] @name = [:name] || [:symbol].to_s if @symbol.nil? || @state_machine.nil? raise ArgumentError, "Missing parameter" end @transition_map = {} @entry_actions = [] @exit_actions = [] end |
Instance Attribute Details
#entry_actions ⇒ Array
Returns an array of Proc
objects called when entering the state.
14 15 16 |
# File 'lib/motion-state-machine/state.rb', line 14 def entry_actions @entry_actions end |
#exit_actions ⇒ Array
Returns an array of Proc
objects called when exiting the state.
18 19 20 |
# File 'lib/motion-state-machine/state.rb', line 18 def exit_actions @exit_actions end |
#name ⇒ String
Returns the state’s name. Only used in debug log output.
10 11 12 |
# File 'lib/motion-state-machine/state.rb', line 10 def name @name end |
#state_machine ⇒ StateMachine::Base (readonly)
Returns the FSM that the state belongs to.
7 8 9 |
# File 'lib/motion-state-machine/state.rb', line 7 def state_machine @state_machine end |
#symbol ⇒ Symbol (readonly)
Returns The state’s identifying symbol.
4 5 6 |
# File 'lib/motion-state-machine/state.rb', line 4 def symbol @symbol end |
#transition_map ⇒ Hash (readonly)
Returns The state machine’s internal transition map (event types -> event values -> possible transitions).
35 36 37 |
# File 'lib/motion-state-machine/state.rb', line 35 def transition_map @transition_map end |
Instance Method Details
#register(transition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Registers a transition in the transition map.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/motion-state-machine/state.rb', line 88 def register(transition) event_type = transition.class.instance_variable_get(:@event_type) event_trigger_value = transition.event_trigger_value transition_map[event_type] ||= {} transitions = (transition_map[event_type][event_trigger_value] ||= []) transitions << transition transition end |
#terminating=(value) ⇒ Object
79 80 81 |
# File 'lib/motion-state-machine/state.rb', line 79 def terminating=(value) @terminating = !!value end |
#terminating? ⇒ Boolean
Returns indicates if the state is a termination state.
75 76 77 |
# File 'lib/motion-state-machine/state.rb', line 75 def terminating? !!@terminating end |