Module: Mongoid::Extensions::BsonDocument

Defined in:
lib/mongoid/extensions/bson_document.rb

Overview

Adds behavior to BSON::Document.

Instance Method Summary collapse

Instance Method Details

#__deep_copy__BSON::Document

Make a deep copy of this document, preserving the BSON::Document type.

Hash#deep_copy returns a plain Hash, which causes field_was to return a different type than the field getter when the stored attribute is a BSON::Document.

Examples:

Make a deep copy of the document.

doc.__deep_copy__

Returns:

  • (BSON::Document)

    The copied document.



17
18
19
20
21
22
23
# File 'lib/mongoid/extensions/bson_document.rb', line 17

def __deep_copy__
  self.class.new.tap do |copy|
    each_pair do |key, value|
      copy.store(key, value.__deep_copy__)
    end
  end
end