Class: Perpetuity::IdentityMap

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

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.



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

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

Instance Method Details

#<<(object) ⇒ Object



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

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

#[](klass, id) ⇒ Object



7
8
9
# File 'lib/perpetuity/identity_map.rb', line 7

def [] klass, id
  @map[klass][id]
end

#ids_for(klass) ⇒ Object



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

def ids_for klass
  @map[klass].keys
end