Module: AASM::Persistence::MongoMapperPersistence::WriteState
- Defined in:
- lib/aasm/persistence/mongo_mapper_persistence.rb
Instance Method Summary collapse
-
#aasm_write_state(state) ⇒ Object
Writes
state
to the state column and persists it to the database using update_attribute (which bypasses validation).
Instance Method Details
#aasm_write_state(state) ⇒ Object
Writes state
to the state column and persists it to the database using update_attribute (which bypasses validation)
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
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/aasm/persistence/mongo_mapper_persistence.rb', line 177 def aasm_write_state(state) old_value = read_attribute(self.class.aasm_column) write_attribute(self.class.aasm_column, state.to_s) unless self.save(:validate => false) write_attribute(self.class.aasm_column, old_value) return false end true end |