module AASM::Persistence::Base
def self.included(base) #:nodoc:
def self.included(base) #:nodoc: base.extend ClassMethods end
def aasm_new_record?
def aasm_new_record? new_record? end
def aasm_read_state(name=:default)
NOTE: intended to be called from an event
foo.current_state # => nil
foo.aasm_state = nil
foo.current_state # => :opened
foo = Foo.find(1)
foo.current_state # => :closed
foo.close
foo.current_state # => :opened
foo = Foo.new
end
end
state :closed
state :opened
aasm :column => :status do
include AASM
class Foo < ActiveRecord::Base
(example provided here for ActiveRecord, but it's true for Mongoid as well):
If it's a new record, and the aasm state column is blank it returns the initial state
Returns the value of the aasm.attribute_name - called from aasm.current_state
def aasm_read_state(name=:default) state = send(self.class.aasm(name).attribute_name) if !state || state.empty? aasm_new_record? ? aasm(name).determine_state_name(self.class.aasm(name).initial_state) : nil else state.to_sym end end