Class: Mongoid::IdentityMap
Overview
Defines behaviour for the identity map in Mongoid.
Instance Method Summary collapse
-
#get(klass, identifier) ⇒ Document
Get a document from the identity map by its id.
-
#remove(document) ⇒ Document?
Remove the document from the identity map.
-
#set(document) ⇒ Document
Puts a document in the identity map, accessed by it’s id.
-
#set_many(document, selector) ⇒ Array<Document>
Set a document in the identity map for the provided selector.
-
#set_one(document, selector) ⇒ Document
Set a document in the identity map for the provided selector.
Methods included from Extensions::Hash::Scoping
Methods included from Extensions::Hash::CriteriaHelpers
#expand_complex_criteria, #extract_id
Instance Method Details
#get(klass, identifier) ⇒ Document
Get a document from the identity map by its id.
18 19 20 21 |
# File 'lib/mongoid/identity_map.rb', line 18 def get(klass, identifier) return nil unless Mongoid.identity_map_enabled? documents_for(klass)[identifier] end |
#remove(document) ⇒ Document?
Remove the document from the identity map.
33 34 35 36 |
# File 'lib/mongoid/identity_map.rb', line 33 def remove(document) return nil unless Mongoid.identity_map_enabled? && document && document.id documents_for(document.class).delete(document.id) end |
#set(document) ⇒ Document
Puts a document in the identity map, accessed by it’s id.
48 49 50 51 |
# File 'lib/mongoid/identity_map.rb', line 48 def set(document) return nil unless Mongoid.identity_map_enabled? && document && document.id documents_for(document.class)[document.id] = document end |
#set_many(document, selector) ⇒ Array<Document>
Set a document in the identity map for the provided selector.
64 65 66 |
# File 'lib/mongoid/identity_map.rb', line 64 def set_many(document, selector) (documents_for(document.class)[selector] ||= []).push(document) end |
#set_one(document, selector) ⇒ Document
Set a document in the identity map for the provided selector.
79 80 81 |
# File 'lib/mongoid/identity_map.rb', line 79 def set_one(document, selector) documents_for(document.class)[selector] = document end |