Class: Perpetuity::IdentityMap

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.



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

def initialize
  @map = Hash.new { |hash, key| hash[key] = {} }
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



3
4
5
# File 'lib/perpetuity/identity_map.rb', line 3

def map
  @map
end

Instance Method Details

#<<(object) ⇒ Object



13
14
15
16
17
# File 'lib/perpetuity/identity_map.rb', line 13

def << object
  klass = object.class
  id = object.instance_variable_get(:@id)
  map[klass][id.to_s] = object.dup
end

#[](klass, id) ⇒ Object



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

def [] klass, id
  map[klass][id.to_s]
end