Class: Celluloid::FSM::State
- Inherits:
-
Object
- Object
- Celluloid::FSM::State
- Defined in:
- lib/celluloid/fsm.rb
Overview
FSM states as declared by Celluloid::FSM.state
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.
134 135 136 137 |
# File 'lib/celluloid/fsm.rb', line 134 def initialize(name, transitions = nil, &block) @name, @block = name, block @transitions = Array(transitions).map { |t| t.to_sym } if transitions end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
132 133 134 |
# File 'lib/celluloid/fsm.rb', line 132 def name @name end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
132 133 134 |
# File 'lib/celluloid/fsm.rb', line 132 def transitions @transitions end |
Instance Method Details
#call(obj) ⇒ Object
139 140 141 |
# File 'lib/celluloid/fsm.rb', line 139 def call(obj) obj.instance_eval(&@block) if @block end |
#valid_transition?(new_state) ⇒ Boolean
143 144 145 146 147 148 |
# File 'lib/celluloid/fsm.rb', line 143 def valid_transition?(new_state) # All transitions are allowed unless expressly return true unless @transitions @transitions.include? new_state.to_sym end |