class Hat::IdentityMap

Attributes

identity_map[RW]

Public Class Methods

new() click to toggle source
# File lib/hat/identity_map.rb, line 5
def initialize
  #Optimised for speed...as tempting as it might be, don't rewrite this to use hash with indifferent access as it is slower.
  @identity_map = {}
end

Public Instance Methods

get(type, id) click to toggle source
# File lib/hat/identity_map.rb, line 10
def get(type, id)
  if id_map = identity_map[type.to_sym]
    id_map[id]
  end
end
inspect() click to toggle source
# File lib/hat/identity_map.rb, line 33
def inspect
  identity_map.inspect
end
put(type, id, object) click to toggle source
# File lib/hat/identity_map.rb, line 16
def put(type, id, object)

  type_symbol = type.to_sym

  unless identity_map[type_symbol]
    identity_map[type_symbol] = {}
  end

  identity_map[type_symbol][id] = object

  self
end
to_hash() click to toggle source
# File lib/hat/identity_map.rb, line 29
def to_hash
  @identity_map
end