Sha256: be8e5dc23e2fc18afbac4e05fd2564575caabf1ef31f7ab6d9ce5055e779f547

Contents?: true

Size: 1012 Bytes

Versions: 10

Compression:

Stored size: 1012 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  # Include this module to get automatic versioning of root level documents.
  # This will add a version field to the +Document+ and a has_many association
  # with all the versions contained in it.
  module Versioning
    extend ActiveSupport::Concern
    included do
      field :version, :type => Integer, :default => 1
      embeds_many :versions, :class_name => self.name
      set_callback :save, :before, :revise
    end

    # 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.
    def revise
      last_version = self.class.first(:conditions => { :_id => id, :version => version })
      if last_version
        self.versions << last_version.clone
        self.version = version + 1
        @modifications["versions"] = [ nil, @attributes["versions"] ] if @modifications
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mongoid-2.0.0.beta.15 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.14 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.13 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.11 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.10 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.7 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.8 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.9 lib/mongoid/versioning.rb
mongoid-2.0.0.beta.12 lib/mongoid/versioning.rb
mongoid-locomotive-2.0.0.beta9 lib/mongoid/versioning.rb