Module: AASM::Persistence::MongoMapperPersistence::InstanceMethods
- Defined in:
- lib/aasm/persistence/mongo_mapper_persistence.rb
Instance Method Summary collapse
-
#aasm_write_state(state, name = :default) ⇒ Object
Writes
stateto the state column and persists it to the database. -
#aasm_write_state_without_persistence(state, name = :default) ⇒ Object
Writes
stateto the state column, 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/aasm/persistence/mongo_mapper_persistence.rb', line 54 def aasm_write_state(state, name=:default) old_value = read_attribute(self.class.aasm(name).attribute_name) write_attribute(self.class.aasm(name).attribute_name, state) success = if aasm_skipping_validations(name) value = aasm_raw_attribute_value(state, name) self.class.where(self.class.primary_key => self.id).update_all(self.class.aasm(name).attribute_name => value) == 1 else self.save end unless success write_attribute(self.class.aasm(name).attribute_name, old_value) return false end true end |
#aasm_write_state_without_persistence(state, name = :default) ⇒ 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
84 85 86 |
# File 'lib/aasm/persistence/mongo_mapper_persistence.rb', line 84 def aasm_write_state_without_persistence(state, name=:default) aasm_write_attribute(state, name) end |