module MongoMapper::Plugins::IdentityMap::ClassMethods

Public Instance Methods

get_from_identity_map(id) click to toggle source

Private - Looks for a document in the identity map

# 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) click to toggle source
Calls superclass method
# 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={}) click to toggle source
Calls superclass method
# 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) click to toggle source
# 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