module MongoMapper::Plugins::Transitions::InstanceMethods
Public Class Methods
new(attrs = {})
click to toggle source
adding back after_initialize callback remove in mongomapper github.com/jnunemaker/mongomapper/commit/f19d7725039fe352603e9809b0c47898cb9598f3
Calls superclass method
# File lib/mm-transitions.rb, line 29 def initialize(attrs = {}) super.tap { run_callbacks(:initialize) } end
Public Instance Methods
reload()
click to toggle source
Calls superclass method
# File lib/mm-transitions.rb, line 33 def reload super.tap do self.class.state_machines.values.each do |sm| remove_instance_variable(sm.current_state_variable) if instance_variable_defined?(sm.current_state_variable) end end end
Protected Instance Methods
read_state(state_machine)
click to toggle source
# File lib/mm-transitions.rb, line 55 def read_state(state_machine) self.state.to_sym end
set_initial_state()
click to toggle source
# File lib/mm-transitions.rb, line 59 def set_initial_state self.state ||= self.class.state_machine.initial_state.to_s end
state_inclusion()
click to toggle source
# File lib/mm-transitions.rb, line 63 def state_inclusion unless self.class.state_machine.states.map{ |s| s.name.to_s }.include?(self.state.to_s) self.errors.add(:state, :inclusion, :value => self.state) end end
write_state(state_machine, state)
click to toggle source
# File lib/mm-transitions.rb, line 43 def write_state(state_machine, state) ivar = state_machine.current_state_variable prev_state = current_state(state_machine.name) instance_variable_set(ivar, state) self.state = state.to_s save! rescue MongoMapper::DocumentNotValid self.state = prev_state.to_s instance_variable_set(ivar, prev_state) raise end