Skip to content
Newer
Older
100644 29 lines (22 sloc) 608 Bytes
218479f @sferik Implement identity map!
authored
1 module Twitter
2
3 # Tracks objects to help ensure that each object gets loaded only once.
4 # See: http://www.martinfowler.com/eaaCatalog/identityMap.html
5 class IdentityMap < Hash
8996c37 @sferik Create proper interface for Twitter::IdentityMap
authored
6
7 # @param klass
8 # @param key
9 # @return [Object]
10 def fetch(klass, key)
11 self[klass] && self[klass][key]
12 end
13
14 # @param key
15 # @param object
16 # @return [Object]
17 def store(key, object)
18 self[object.class] ||= {}
19 self[object.class][key] = object
20 end
21
218479f @sferik Implement identity map!
authored
22 end
23
5503704 @sferik IdentityMapKeyError is an IndexError
authored
24 # Inherit from KeyError when Ruby 1.8 compatibility is removed
25 class IdentityMapKeyError < ::IndexError
5b549e3 @stve let Twitter::Base#fetch accept a block
stve authored
26 end
27
218479f @sferik Implement identity map!
authored
28 end
Something went wrong with that request. Please try again.