Defines behaviour for the identity map in Mongoid.
Get a document from the identity map by its id.
@example Get the document from the map.
map.get(Person, id)
@param [ Class ] klass The class of the document. @param [ Object, Hash ] idenfier The document id or selector.
@return [ Document ] The matching document.
@since 2.1.0
# File lib/mongoid/identity_map.rb, line 17 def get(klass, identifier) return nil unless Mongoid.identity_map_enabled? documents_for(klass)[identifier] end
Remove the document from the identity map.
@example Remove the document.
map.removed(person)
@param [ Document ] document The document to remove.
@return [ Document, nil ] The removed document.
@since 2.1.0
# File lib/mongoid/identity_map.rb, line 32 def remove(document) return nil unless Mongoid.identity_map_enabled? && document && document.id documents_for(document.class).delete(document.id) end
Puts a document in the identity map, accessed by it’s id.
@example Put the document in the map.
identity_map.set(document)
@param [ Document ] document The document to place in the map.
@return [ Document ] The provided document.
@since 2.1.0
# File lib/mongoid/identity_map.rb, line 47 def set(document) return nil unless Mongoid.identity_map_enabled? && document && document.id documents_for(document.class)[document.id] = document end
Set a document in the identity map for the provided selector.
@example Set the document in the map.
identity_map.set_selector(document, { :person_id => person.id })
@param [ Document ] document The document to set. @param [ Hash ] selector The selector to identify it.
@return [ Array<Document> ] The documents.
@since 2.2.0
# File lib/mongoid/identity_map.rb, line 63 def set_many(document, selector) (documents_for(document.class)[selector] ||= []).push(document) end
Set a document in the identity map for the provided selector.
@example Set the document in the map.
identity_map.set_selector(document, { :person_id => person.id })
@param [ Document ] document The document to set. @param [ Hash ] selector The selector to identify it.
@return [ Document ] The matching document.
@since 2.2.0
# File lib/mongoid/identity_map.rb, line 78 def set_one(document, selector) documents_for(document.class)[selector] = document end
Generated with the Darkfish Rdoc Generator 2.