module AASM::Persistence::NoBrainerPersistence::InstanceMethods

def aasm_ensure_initial_state


foo.aasm_state # => nil
foo.valid?
foo.aasm_state = nil
foo.aasm_state # => 1
foo = Foo.find(:first)


foo.aasm_state # => "open" (where :open is the initial state)
foo.valid?
foo.aasm_state # => nil
foo = Foo.new

that the initial state gets populated before validation on create
Ensures that if the aasm_state column is nil and the record is new
def aasm_ensure_initial_state
  AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |name|
    aasm_column = self.class.aasm(name).attribute_name
    aasm(name).enter_initial_state if !read_attribute(aasm_column) || read_attribute(aasm_column).empty?
  end
end

def aasm_raise_invalid_record

def aasm_raise_invalid_record
  raise NoBrainer::Error::DocumentInvalid.new(self)
end

def aasm_read_attribute(name)

def aasm_read_attribute(name)
  read_attribute(name)
end

def aasm_save

def aasm_save
  self.save
end

def aasm_supports_transactions?

def aasm_supports_transactions?
  false
end

def aasm_update_column(attribute_name, value)

def aasm_update_column(attribute_name, value)
  write_attribute(attribute_name, value)
  save(validate: false)
  true
end

def aasm_write_attribute(name, value)

def aasm_write_attribute(name, value)
  write_attribute(name, value)
end