Skip to content

Commit

Permalink
decouple identity map storage and instantiation on Twitter::Identity
Browse files Browse the repository at this point in the history
  • Loading branch information
stve committed Jul 11, 2012
1 parent f2eac39 commit 5058160
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/twitter/identity.rb
Expand Up @@ -9,19 +9,23 @@ def self.fetch(attrs)
id && @@identity_map[self][id] && @@identity_map[self][id].update(attrs) || super(attrs)
end

# Stores an object in the identity map.
#
# @param attrs [Hash]
# @return [Twitter::Base]
def self.store(object)
@@identity_map[self] ||= {}
object.id && @@identity_map[self][object.id] = object || super(object)
end

# Initializes a new object
#
# @param attrs [Hash]
# @raise [ArgumentError] Error raised when supplied argument is missing an :id key.
# @return [Twitter::Base]
def initialize(attrs={})
self.update(attrs)
if self.id
@@identity_map[self.class] ||= {}
@@identity_map[self.class][self.id] = self
else
raise ArgumentError, "argument must have an :id key"
end
raise ArgumentError, "argument must have an :id key" unless self.id
end

# @param other [Twitter::Identity]
Expand Down

0 comments on commit 5058160

Please sign in to comment.