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.
169 170 171 172 173 |
# File 'lib/celluloid/fsm.rb', line 169 def initialize(name, transitions = nil, &block) @name, @block = name, block @transitions = nil @transitions = Array(transitions).map(&:to_sym) if transitions end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
167 168 169 |
# File 'lib/celluloid/fsm.rb', line 167 def name @name end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
167 168 169 |
# File 'lib/celluloid/fsm.rb', line 167 def transitions @transitions end |
Instance Method Details
#call(obj) ⇒ Object
175 176 177 |
# File 'lib/celluloid/fsm.rb', line 175 def call(obj) obj.instance_eval(&@block) if @block end |
#valid_transition?(new_state) ⇒ Boolean
179 180 181 182 183 184 |
# File 'lib/celluloid/fsm.rb', line 179 def valid_transition?(new_state) # All transitions are allowed unless expressly return true unless @transitions @transitions.include? new_state.to_sym end |