Class: Playapi::Identity
Direct Known Subclasses
Class Method Summary collapse
- .fetch(attrs) ⇒ Object
-
.store(object) ⇒ Twitter::Identity
Stores an object in the identity map.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #id ⇒ Integer
-
#initialize(attrs = {}) ⇒ Twitter::Identity
constructor
Initializes a new object.
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
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.
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
39 40 41 |
# File 'lib/playapi/identity.rb', line 39 def ==(other) super || attr_equal(:id, other) || attrs_equal(other) end |
#id ⇒ Integer
44 45 46 |
# File 'lib/playapi/identity.rb', line 44 def id @attrs[:id] end |