Class: Vorpal::IdentityMap

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

Overview

Maps DB rows to Entities

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.



4
5
6
# File 'lib/vorpal/identity_map.rb', line 4

def initialize
  @entities = {}
end

Instance Method Details

#get(db_row) ⇒ Object



8
9
10
# File 'lib/vorpal/identity_map.rb', line 8

def get(db_row)
  @entities[key(db_row)]
end

#get_and_set(db_row) ⇒ Object



16
17
18
19
20
21
# File 'lib/vorpal/identity_map.rb', line 16

def get_and_set(db_row)
  entity = get(db_row)
  entity = yield if entity.nil?
  set(db_row, entity)
  entity
end

#map(key_objects) ⇒ Object



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

def map(key_objects)
  key_objects.map { |k| @entities[key(k)] }
end

#set(db_row, entity) ⇒ Object



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

def set(db_row, entity)
  @entities[key(db_row)] = entity
end