Sha256: 116404b6c659543df916b978f9bd2f7ed258ee0df6081b1b1e318c346294ea51

Contents?: true

Size: 807 Bytes

Versions: 13

Compression:

Stored size: 807 Bytes

Contents

# encoding: utf-8
module Mongoid

  # This module contains the behaviour of Mongoid's clone/dup of documents.
  module Copyable
    extend ActiveSupport::Concern

    # Clone or dup the current +Document+. This will return all attributes with
    # the exception of the document's id and versions, and will reset all the
    # instance variables.
    #
    # This clone also includes embedded documents.
    #
    # @example Clone the document.
    #   document.clone
    #
    # @param [ Document ] other The document getting cloned.
    #
    # @return [ Document ] The new document.
    def clone
      attrs = as_document.except("_id")
      if attrs.delete("versions")
        attrs["version"] = 1
      end
      self.class.new(attrs, without_protection: true)
    end
    alias :dup :clone
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
mongoid-3.0.19 lib/mongoid/copyable.rb
mongoid-3.0.18 lib/mongoid/copyable.rb
mongoid-3.0.17 lib/mongoid/copyable.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/copyable.rb
mongoid-3.0.16 lib/mongoid/copyable.rb
mongoid-3.0.15 lib/mongoid/copyable.rb
mongoid-3.0.14 lib/mongoid/copyable.rb
mongoid-3.0.13 lib/mongoid/copyable.rb
mongoid-3.0.12 lib/mongoid/copyable.rb
mongoid-3.0.11 lib/mongoid/copyable.rb
mongoid-3.0.10 lib/mongoid/copyable.rb
mongoid-3.0.9 lib/mongoid/copyable.rb
mongoid-3.0.6 lib/mongoid/copyable.rb