Class: Plangrade::Resources::IdentityMap
- Inherits:
-
Object
- Object
- Plangrade::Resources::IdentityMap
- Defined in:
- lib/plangrade/resources/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.
7 8 9 10 |
# File 'lib/plangrade/resources/identity_map.rb', line 7 def initialize @map = {} @size = 0 end |
Instance Method Details
#get(key, default = nil) ⇒ Hash
Note:
retrives key from identity map
16 17 18 |
# File 'lib/plangrade/resources/identity_map.rb', line 16 def get(key, default=nil) @map["#{key}"] || default end |
#purge! ⇒ Hash
clears the entire identity map
39 40 41 |
# File 'lib/plangrade/resources/identity_map.rb', line 39 def purge! @map = {} end |
#put(key, value) ⇒ Hash
Note:
inserts a hash of attributes into identity map
24 25 26 27 28 29 |
# File 'lib/plangrade/resources/identity_map.rb', line 24 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
33 34 35 |
# File 'lib/plangrade/resources/identity_map.rb', line 33 def size @map.keys.count end |