Class/Module Index [+]

Quicksearch

Mongoid::Copyable

This module contains the behaviour of Mongoid’s clone/dup of documents.

Constants

COPYABLES

Protected Instance Methods

initialize_copy(other) click to toggle source

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

@example Dup the document.

document.dup

@param [ Document ] other The document getting cloned.

@return [ Document ] The new document.

# File lib/mongoid/copyable.rb, line 32
def initialize_copy(other)
  @attributes = other.as_document
  instance_variables.each { |name| remove_instance_variable(name) }
  COPYABLES.each do |name|
    value = other.instance_variable_get(name)
    instance_variable_set(name, value ? value.dup : nil)
  end
  attributes.delete("_id")
  if attributes.delete("versions")
    attributes["version"] = 1
  end
  @new_record = true
  identify
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.