Class: DataMapper::IdentityMap

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

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.



6
7
8
# File 'lib/data_mapper/identity_map.rb', line 6

def initialize
  @cache = Hash.new { |h,k| h[k] = Support::WeakHash.new }
end

Instance Method Details

#get(klass, key) ⇒ Object



10
11
12
# File 'lib/data_mapper/identity_map.rb', line 10

def get(klass, key)
  @cache[klass][key]
end

#set(instance) ⇒ Object



14
15
16
17
18
# File 'lib/data_mapper/identity_map.rb', line 14

def set(instance)
  raise "Can't store an instance with a nil key in the IdentityMap" if instance.key == nil
    
  @cache[instance.class][instance.key] = instance
end