Module: AASM::Persistence::OhmPersistence::InstanceMethods

Defined in:
lib/aasm/persistence/ohm_persistence.rb

Instance Method Summary collapse

Instance Method Details

#aasm_write_state(state) ⇒ Object

Writes state to the state column and persists it to the database

foo = Foo.find(1)
foo.aasm.current_state # => :opened
foo.close!
foo.aasm.current_state # => :closed
Foo.find(1).aasm.current_state # => :closed

NOTE: intended to be called from an event



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/aasm/persistence/ohm_persistence.rb', line 63

def aasm_write_state(state)
  old_value = self.send(self.class.aasm_column.to_sym)
  aasm_write_state_without_persistence(state)

  success = self.save

  unless success
    aasm_write_state_without_persistence(old_value)
    return false
  end

  true
end

#aasm_write_state_without_persistence(state) ⇒ Object

Writes state to the state column, but does not persist it to the database

foo = Foo.find(1)
foo.aasm.current_state # => :opened
foo.close
foo.aasm.current_state # => :closed
Foo.find(1).aasm.current_state # => :opened
foo.save
foo.aasm.current_state # => :closed
Foo.find(1).aasm.current_state # => :closed

NOTE: intended to be called from an event



89
90
91
# File 'lib/aasm/persistence/ohm_persistence.rb', line 89

def aasm_write_state_without_persistence(state)
  self.send(:"#{self.class.aasm_column}=", state.to_s)
end

#before_createObject



48
49
50
51
# File 'lib/aasm/persistence/ohm_persistence.rb', line 48

def before_create
  super
  aasm_ensure_initial_state
end