Sha256: 7ebcf784c525265bb0a69d0cfb763ade45cbf3498d502c5f97e62475d755fb39

Contents?: true

Size: 781 Bytes

Versions: 6

Compression:

Stored size: 781 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)
    end
    alias :dup :clone
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongoid-3.0.5 lib/mongoid/copyable.rb
mongoid-3.0.4 lib/mongoid/copyable.rb
mongoid-3.0.3 lib/mongoid/copyable.rb
mongoid-3.0.2 lib/mongoid/copyable.rb
mongoid-3.0.1 lib/mongoid/copyable.rb
mongoid-3.0.0 lib/mongoid/copyable.rb