Module: Mongoid::StateMachine::InstanceMethods

Defined in:
lib/mongoid/state_machine.rb

Instance Method Summary collapse

Instance Method Details

#current_stateObject

Returns the current state the object is in, as a Ruby symbol.



152
153
154
# File 'lib/mongoid/state_machine.rb', line 152

def current_state
  self.send(self.class.state_column).to_sym
end

#next_state_for_event(event) ⇒ Object

Returns what the next state for a given event would be, as a Ruby symbol.



157
158
159
160
# File 'lib/mongoid/state_machine.rb', line 157

def next_state_for_event(event)
  ns = next_states_for_event(event)
  ns.empty? ? nil : ns.first.to.to_sym
end

#next_states_for_event(event) ⇒ Object



162
163
164
165
166
# File 'lib/mongoid/state_machine.rb', line 162

def next_states_for_event(event)
  self.class.read_inheritable_attribute(:transition_table)[event.to_sym].select do |s|
    s.from == current_state.to_s
  end
end

#run_initial_state_actionsObject



145
146
147
148
149
# File 'lib/mongoid/state_machine.rb', line 145

def run_initial_state_actions
  initial = self.class.read_inheritable_attribute(:states)[self.class.initial_state.to_s]
  initial.entering(self)
  initial.entered(self)
end

#set_initial_stateObject

:nodoc:



141
142
143
# File 'lib/mongoid/state_machine.rb', line 141

def set_initial_state #:nodoc:
  send("#{self.class.state_column}=", self.class.initial_state.to_s)
end