Module: AASM::Persistence::ORM
- Defined in:
- lib/aasm/persistence/orm.rb
Overview
This module adds transactional support for any database that supports it. This includes rollback capability and rollback/commit callbacks.
Instance Method Summary collapse
-
#aasm_write_state(state, name = :default) ⇒ Object
Writes
state
to the state column and persists it to the database. -
#aasm_write_state_without_persistence(state, name = :default) ⇒ Object
Writes
state
to the state field, but does not persist it to the database.
Instance Method Details
#aasm_write_state(state, name = :default) ⇒ 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aasm/persistence/orm.rb', line 16 def aasm_write_state(state, name=:default) attribute_name = self.class.aasm(name).attribute_name old_value = aasm_read_attribute(attribute_name) aasm_write_state_attribute state, name success = if aasm_skipping_validations(name) aasm_update_column(attribute_name, aasm_raw_attribute_value(state, name)) else aasm_save end unless success aasm_rollback(name, old_value) aasm_raise_invalid_record if aasm_whiny_persistence(name) end success end |
#aasm_write_state_without_persistence(state, name = :default) ⇒ Object
Writes state
to the state field, 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
47 48 49 |
# File 'lib/aasm/persistence/orm.rb', line 47 def aasm_write_state_without_persistence(state, name=:default) aasm_write_state_attribute(state, name) end |