class Object
Public Class Methods
included(base)
click to toggle source
# File lib/enum_aasm.rb, line 51 def self.included(base) base.send(:include, AASM::Persistence::Base) base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods) base.before_validation(:aasm_ensure_initial_state, :on => :create) # ensure initial aasm state even when validations are skipped base.before_create(:aasm_ensure_initial_state) # ensure state is in the list of states base.validate :aasm_validate_states end
Public Instance Methods
aasm_write_state(state)
click to toggle source
Patched to use the enumerated attribute
# File lib/enum_aasm.rb, line 15 def aasm_write_state(state) attr_name = self.class.aasm_column old_value = self.__send__(attr_name) self.__send__("#{attr_name}=", state) success = if AASM::StateMachine[self.class].config.skip_validation_on_save self.update_attribute(attr_name, state) else self.save end if success true else self.__send__("#{attr_name}=", old_value) false end end
aasm_write_state_without_persistence(state)
click to toggle source
Patched to use the enumerated attribute
# File lib/enum_aasm.rb, line 34 def aasm_write_state_without_persistence(state) self.__send__("#{self.class.aasm_column}=", state) end
state(name, *args)
click to toggle source
Scopes need to be disabled. PowerEnum already provides this functionality
# File lib/enum_aasm.rb, line 43 def state(name, *args) state_without_scope(name, *args) end