Class: ActiveRecord::Base::ThreadIdentityMap::ClassIdMap
- Inherits:
-
Object
- Object
- ActiveRecord::Base::ThreadIdentityMap::ClassIdMap
- Defined in:
- lib/identity_map/cache.rb
Overview
ClassIdMap do the job of properly use typecasted id
value of model object for search in a cache
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, v) ⇒ Object
- #delete(id) ⇒ Object
-
#initialize(klass) ⇒ ClassIdMap
constructor
A new instance of ClassIdMap.
Constructor Details
#initialize(klass) ⇒ ClassIdMap
Returns a new instance of ClassIdMap.
7 8 9 10 11 12 |
# File 'lib/identity_map/cache.rb', line 7 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
14 15 16 17 |
# File 'lib/identity_map/cache.rb', line 14 def [](id) @object.id = id @objects[@object.id] end |
#[]=(id, v) ⇒ Object
19 20 21 22 |
# File 'lib/identity_map/cache.rb', line 19 def []=(id, v) @object.id = id @objects[@object.id] = v end |
#delete(id) ⇒ Object
24 25 26 27 |
# File 'lib/identity_map/cache.rb', line 24 def delete(id) @object.id = id @objects.delete(@object.id) end |