Class: Celluloid::FSM::State

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/fsm.rb

Overview

FSM states as declared by Celluloid::FSM.state

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, transitions = nil, &block) ⇒ State


167
168
169
170
171
# File 'lib/celluloid/fsm.rb', line 167

def initialize(name, transitions = nil, &block)
  @name, @block = name, block
  @transitions = nil
  @transitions = Array(transitions).map(&:to_sym) if transitions
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


165
166
167
# File 'lib/celluloid/fsm.rb', line 165

def name
  @name
end

#transitionsObject (readonly)

Returns the value of attribute transitions


165
166
167
# File 'lib/celluloid/fsm.rb', line 165

def transitions
  @transitions
end

Instance Method Details

#call(obj) ⇒ Object


173
174
175
# File 'lib/celluloid/fsm.rb', line 173

def call(obj)
  obj.instance_eval(&@block) if @block
end

#valid_transition?(new_state) ⇒ Boolean


177
178
179
180
181
182
# File 'lib/celluloid/fsm.rb', line 177

def valid_transition?(new_state)
  # All transitions are allowed unless expressly
  return true unless @transitions

  @transitions.include? new_state.to_sym
end