Class: MongoidIdentityMap::IdentityMap

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid_identity_map/identity_map.rb

Class Method Summary collapse

Class Method Details

.clearObject



21
22
23
# File 'lib/mongoid_identity_map/identity_map.rb', line 21

def clear
  Thread.current[:mongoid_identity_map_current_thread_hash] = nil
end

.fetch(key) ⇒ Object



13
14
15
# File 'lib/mongoid_identity_map/identity_map.rb', line 13

def fetch(key)
  get(key) || set(key, yield)
end

.get(key) ⇒ Object



9
10
11
# File 'lib/mongoid_identity_map/identity_map.rb', line 9

def get(key)
  thread_local_hash[key]
end

.remove(model) ⇒ Object



17
18
19
# File 'lib/mongoid_identity_map/identity_map.rb', line 17

def remove(model)
  thread_local_hash.delete_if {|key, value| value == model}
end

.set(key, model) ⇒ Object



5
6
7
# File 'lib/mongoid_identity_map/identity_map.rb', line 5

def set(key, model)
  thread_local_hash[key] = thread_local_hash.values.detect {|value| value == model} || model
end