class Vorpal::IdentityMap
Maps DB rows to Entities
Public Class Methods
new()
click to toggle source
# File lib/vorpal/identity_map.rb, line 4 def initialize @entities = {} end
Public Instance Methods
get(db_row)
click to toggle source
# File lib/vorpal/identity_map.rb, line 8 def get(db_row) @entities[key(db_row)] end
get_and_set(db_row) { || ... }
click to toggle source
# 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)
click to toggle source
# File lib/vorpal/identity_map.rb, line 23 def map(key_objects) key_objects.map { |k| @entities[key(k)] } end
set(db_row, entity)
click to toggle source
# File lib/vorpal/identity_map.rb, line 12 def set(db_row, entity) @entities[key(db_row)] = entity end
Private Instance Methods
key(db_row)
click to toggle source
# File lib/vorpal/identity_map.rb, line 29 def key(db_row) return nil unless db_row raise "Cannot map a DB row without an id '#{db_row.inspect}' to an entity." if db_row.id.nil? raise "Cannot map a DB row without a Class with a name '#{db_row.inspect}' to an entity." if db_row.class.name.nil? [db_row.id, db_row.class.name] end