Module: MongoMapper::Plugins::IdentityMap::ClassMethods
- Defined in:
- lib/mongo_mapper/plugins/identity_map.rb
Instance Method Summary collapse
-
#get_from_identity_map(id) ⇒ Object
Private - Looks for a document in the identity map.
- #load(attrs, with_cast = false) ⇒ Object
- #query(opts = {}) ⇒ Object
- #remove_documents_from_map(*documents) ⇒ Object
Instance Method Details
#get_from_identity_map(id) ⇒ Object
Private - Looks for a document in the identity map
56 57 58 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 56 def get_from_identity_map(id) IdentityMap.repository[IdentityMap.key(self, id)] end |
#load(attrs, with_cast = false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 72 def load(attrs, with_cast = false) return super unless Thread.current[:mongo_mapper_identity_map_enabled] return nil unless attrs document = get_from_identity_map(attrs['_id']) if !document document = super document.add_to_identity_map end document end |
#query(opts = {}) ⇒ Object
60 61 62 63 64 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 60 def query(opts={}) super.tap do |query| query.identity_map = self if Thread.current[:mongo_mapper_identity_map_enabled] end end |
#remove_documents_from_map(*documents) ⇒ Object
66 67 68 69 70 |
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 66 def remove_documents_from_map(*documents) documents.flatten.compact.each do |document| document.remove_from_identity_map end end |