Class: ActiveRecord::Base::ThreadIdentityMap::ClassIdMap

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

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ClassIdMap

Returns a new instance of ClassIdMap.



5
6
7
8
9
10
# File 'lib/identity_map/cache.rb', line 5

def initialize(klass)
  @objects = {}
  @object = klass.allocate
  @object.instance_variable_set(:@attributes, {:id=>nil})
  @object.instance_variable_set(:@attributes_cache, {})
end

Instance Method Details

#[](id) ⇒ Object



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

def [](id)
  @object.id = id
  @objects[@object.id]
end

#[]=(id, v) ⇒ Object



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

def []=(id, v)
  @object.id = id
  @objects[@object.id] = v
end

#delete(id) ⇒ Object



22
23
24
25
# File 'lib/identity_map/cache.rb', line 22

def delete(id)
  @object.id = id
  @objects.delete(@object.id)
end