Class: HttpApiTools::IdentityMap
- Inherits:
-
Object
- Object
- HttpApiTools::IdentityMap
- Defined in:
- lib/http_api_tools/identity_map.rb
Instance Method Summary collapse
- #get(type, id) ⇒ Object
-
#initialize ⇒ IdentityMap
constructor
A new instance of IdentityMap.
- #inspect ⇒ Object
- #put(type, id, object) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ IdentityMap
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 |
#inspect ⇒ Object
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_hash ⇒ Object
29 30 31 |
# File 'lib/http_api_tools/identity_map.rb', line 29 def to_hash @identity_map end |