Class: Listen::FSM::State
- Inherits:
-
Object
- Object
- Listen::FSM::State
- Defined in:
- lib/listen/fsm.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(name, transitions = nil, &block) ⇒ State
constructor
A new instance of State.
- #valid_transition?(new_state) ⇒ Boolean
Constructor Details
#initialize(name, transitions = nil, &block) ⇒ State
Returns a new instance of State.
113 114 115 116 117 118 |
# File 'lib/listen/fsm.rb', line 113 def initialize(name, transitions = nil, &block) @name = name @block = block @transitions = nil @transitions = Array(transitions).map(&:to_sym) if transitions end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
111 112 113 |
# File 'lib/listen/fsm.rb', line 111 def name @name end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
111 112 113 |
# File 'lib/listen/fsm.rb', line 111 def transitions @transitions end |
Instance Method Details
#call(obj) ⇒ Object
120 121 122 |
# File 'lib/listen/fsm.rb', line 120 def call(obj) obj.instance_eval(&@block) if @block end |
#valid_transition?(new_state) ⇒ Boolean
124 125 126 127 128 129 |
# File 'lib/listen/fsm.rb', line 124 def valid_transition?(new_state) # All transitions are allowed unless expressly return true unless @transitions @transitions.include? new_state.to_sym end |