Class: Yammer::Resources::IdentityMap

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

Defined Under Namespace

Classes: InvalidKeyError

Instance Method Summary collapse

Constructor Details

#initializeIdentityMap

Returns a new instance of IdentityMap.


21
22
23
24
# File 'lib/yammer/resources/identity_map.rb', line 21

def initialize
  @map  = {}
  @size = 0
end

Instance Method Details

#get(key, default = nil) ⇒ Hash

Note:

retrives key from identity map

Parameters:

  • key (string)
  • default (Hash) (defaults to: nil)

Returns:

  • (Hash)

30
31
32
# File 'lib/yammer/resources/identity_map.rb', line 30

def get(key, default=nil)
  @map["#{key}"] || default
end

#purge!Hash

clears the entire identity map

Returns:

  • (Hash)

53
54
55
# File 'lib/yammer/resources/identity_map.rb', line 53

def purge!
  @map = {}
end

#put(key, value) ⇒ Hash

Note:

inserts a hash of attributes into identity map

Parameters:

  • key (string)
  • value (Hash)

Returns:

  • (Hash)

38
39
40
41
42
43
# File 'lib/yammer/resources/identity_map.rb', line 38

def put(key, value)
  if key.nil? || key.empty?
    raise InvalidKeyError.new
  end
  @map["#{key}"] = value
end

#sizeInteger

Note:

returns the current size of identity map

Returns:

  • (Integer)

47
48
49
# File 'lib/yammer/resources/identity_map.rb', line 47

def size
  @map.keys.count
end