Class: Yammer::IdentityMap
- Inherits:
-
Object
- Object
- Yammer::IdentityMap
- Defined in:
- lib/yammer/identity_map.rb
Defined Under Namespace
Classes: InvalidKeyError
Instance Method Summary collapse
- #get(key, default = nil) ⇒ Hash
-
#initialize ⇒ IdentityMap
constructor
A new instance of IdentityMap.
-
#purge! ⇒ Hash
clears the entire identity map.
- #put(key, value) ⇒ Hash
- #size ⇒ Integer
Constructor Details
#initialize ⇒ IdentityMap
Returns a new instance of IdentityMap.
6 7 8 9 |
# File 'lib/yammer/identity_map.rb', line 6 def initialize @map = {} @size = 0 end |
Instance Method Details
#get(key, default = nil) ⇒ Hash
Note:
retrives key from identity map
15 16 17 |
# File 'lib/yammer/identity_map.rb', line 15 def get(key, default=nil) @map["#{key}"] || default end |
#purge! ⇒ Hash
clears the entire identity map
38 39 40 |
# File 'lib/yammer/identity_map.rb', line 38 def purge! @map = {} end |
#put(key, value) ⇒ Hash
Note:
inserts a hash of attributes into identity map
23 24 25 26 27 28 |
# File 'lib/yammer/identity_map.rb', line 23 def put(key, value) if key.nil? || key.empty? raise InvalidKeyError.new end @map["#{key}"] = value end |
#size ⇒ Integer
Note:
returns the current size of identity map
32 33 34 |
# File 'lib/yammer/identity_map.rb', line 32 def size @map.keys.count end |