Class: Playapi::Identity

Inherits:
Base
  • Object
show all
Defined in:
lib/playapi/identity.rb

Direct Known Subclasses

Account, Campaign, Entity, Feature, Interaction

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], attr_reader, #attrs, fetch_or_new, from_response, identity_map, #update

Constructor Details

#initialize(attrs = {}) ⇒ Twitter::Identity

Initializes a new object

Parameters:

  • attrs (Hash) (defaults to: {})

Raises:

  • (ArgumentError)

    Error raised when supplied argument is missing an :id key.



32
33
34
35
# File 'lib/playapi/identity.rb', line 32

def initialize(attrs={})
  super
  raise ArgumentError, "argument must have an :id key" unless id
end

Class Method Details

.fetch(attrs) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/playapi/identity.rb', line 6

def self.fetch(attrs)
  return unless identity_map

  id = attrs[:id]
  if id  && object = identity_map.fetch(id)
    return object.update(attrs)
  end

  return yield if block_given?
  raise "Not Found!"
end

.store(object) ⇒ Twitter::Identity

Stores an object in the identity map.

Parameters:

  • object (Object)

Returns:

  • (Twitter::Identity)


22
23
24
25
# File 'lib/playapi/identity.rb', line 22

def self.store(object)
  return object unless identity_map
  identity_map.store(object.id, object)
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Twitter::Identity)

Returns:

  • (Boolean)


39
40
41
# File 'lib/playapi/identity.rb', line 39

def ==(other)
  super || attr_equal(:id, other) || attrs_equal(other)
end

#idInteger

Returns:

  • (Integer)


44
45
46
# File 'lib/playapi/identity.rb', line 44

def id
  @attrs[:id]
end