Method: Mongoid::Versioning#revise
- Defined in:
- lib/mongoid/versioning.rb
#revise ⇒ Object
Create a new version of the Document. This will load the previous document from the database and set it as the next version before saving the current document. It then increments the version number. If a #max_versions limit is set in the model and it’s exceeded, the oldest version gets discarded.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mongoid/versioning.rb', line 36 def revise previous = previous_revision if previous && versioned_attributes_changed? versions.build( previous.versioned_attributes, :without_protection => true ).attributes.delete("_id") if version_max.present? && versions.length > version_max deleted = versions.first if deleted.paranoid? versions.delete_one(deleted) collection.update( atomic_selector, { "$pull" => { "versions" => { "version" => deleted.version }}} ) else versions.delete(deleted) end end self.version = (version || 1 ) + 1 end end |