Class: HttpApiTools::IdentityMap

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

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.



5
6
7
8
# File 'lib/http_api_tools/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

Instance Method Details

#get(type, id) ⇒ Object



10
11
12
13
14
# File 'lib/http_api_tools/identity_map.rb', line 10

def get(type, id)
  if id_map = identity_map[type.to_sym]
    id_map[id]
  end
end

#inspectObject



33
34
35
# File 'lib/http_api_tools/identity_map.rb', line 33

def inspect
  identity_map.inspect
end

#put(type, id, object) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/http_api_tools/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_hashObject



29
30
31
# File 'lib/http_api_tools/identity_map.rb', line 29

def to_hash
  @identity_map
end