Class: Celluloid::FSM::State

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/celluloid/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

Returns a new instance of State.



124
125
126
127
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 124

def initialize(name, transitions = nil, &block)
  @name, @block = name, block
  @transitions = Array(transitions).map { |t| t.to_sym } if transitions
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



122
123
124
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 122

def name
  @name
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



122
123
124
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 122

def transitions
  @transitions
end

Instance Method Details

#call(obj) ⇒ Object



129
130
131
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 129

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

#valid_transition?(new_state) ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
136
137
138
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 133

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

  @transitions.include? new_state.to_sym
end