Skip to content

Commit

Permalink
Rename @attributes to @attrs to avoid collision with Twitter::Place#a…
Browse files Browse the repository at this point in the history
…ttributes
  • Loading branch information
sferik committed Oct 19, 2011
1 parent 13d95f0 commit 918aca1
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
14 changes: 7 additions & 7 deletions lib/twitter/base.rb
@@ -1,20 +1,20 @@
module Twitter
class Base
attr_accessor :attributes
alias :to_hash :attributes
attr_accessor :attrs
alias :to_hash :attrs

def self.lazy_attr_reader(*attributes)
attributes.each do |attribute|
def self.lazy_attr_reader(*attrs)
attrs.each do |attribute|
class_eval do
define_method attribute do
instance_variable_get("@attributes")[attribute.to_s]
instance_variable_get("@attrs")[attribute.to_s]
end
end
end
end

def initialize(attributes = {})
@attributes = attributes.dup
def initialize(attrs = {})
@attrs = attrs.dup
end

def [](method)
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/configuration.rb
Expand Up @@ -8,7 +8,7 @@ class Configuration < Twitter::Base
:non_username_paths, :photo_size_limit, :short_url_length, :short_url_length_https

def photo_sizes
@photo_sizes ||= Array(@attributes['photo_sizes']).each_with_object({}) do |(key, value), object|
@photo_sizes ||= Array(@attrs['photo_sizes']).each_with_object({}) do |(key, value), object|
object[key] = Twitter::Size.new(value)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/creatable.rb
Expand Up @@ -4,7 +4,7 @@ module Twitter
module Creatable

def created_at
@created_at ||= Time.parse(@attributes['created_at']) unless @attributes['created_at'].nil?
@created_at ||= Time.parse(@attrs['created_at']) unless @attrs['created_at'].nil?
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/direct_message.rb
Expand Up @@ -12,11 +12,11 @@ def ==(other)
end

def recipient
@recipient ||= Twitter::User.new(@attributes['recipient']) unless @attributes['recipient'].nil?
@recipient ||= Twitter::User.new(@attrs['recipient']) unless @attrs['recipient'].nil?
end

def sender
@sender ||= Twitter::User.new(@attributes['sender']) unless @attributes['sender'].nil?
@sender ||= Twitter::User.new(@attrs['sender']) unless @attrs['sender'].nil?
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/list.rb
Expand Up @@ -12,7 +12,7 @@ def ==(other)
end

def user
@user ||= Twitter::User.new(@attributes['user']) unless @attributes['user'].nil?
@user ||= Twitter::User.new(@attrs['user']) unless @attrs['user'].nil?
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/photo.rb
Expand Up @@ -12,7 +12,7 @@ def ==(other)
end

def sizes
@sizes ||= Array(@attributes['sizes']).each_with_object({}) do |(key, value), object|
@sizes ||= Array(@attrs['sizes']).each_with_object({}) do |(key, value), object|
object[key] = Twitter::Size.new(value)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/place.rb
Expand Up @@ -11,19 +11,19 @@ def ==(other)
end

def bounding_box
@bounding_box ||= Twitter::GeoFactory.new(@attributes['bounding_box']) unless @attributes['bounding_box'].nil?
@bounding_box ||= Twitter::GeoFactory.new(@attrs['bounding_box']) unless @attrs['bounding_box'].nil?
end

def country_code
@country_code ||= @attributes['country_code'] || @attributes['countryCode']
@country_code ||= @attrs['country_code'] || @attrs['countryCode']
end

def parent_id
@parent_id ||= @attributes['parentid']
@parent_id ||= @attrs['parentid']
end

def place_type
@place_type ||= @attributes['place_type'] || @attributes['placeType'] && @attributes['placeType']['name']
@place_type ||= @attrs['place_type'] || @attrs['placeType'] && @attrs['placeType']['name']
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rate_limit_status.rb
Expand Up @@ -5,7 +5,7 @@ class RateLimitStatus < Twitter::Base
lazy_attr_reader :hourly_limit, :remaining_hits, :reset_time_in_seconds

def reset_time
@reset_time ||= Time.parse(@attributes['reset_time']) unless @attributes['reset_time'].nil?
@reset_time ||= Time.parse(@attrs['reset_time']) unless @attrs['reset_time'].nil?
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/relationship.rb
Expand Up @@ -5,11 +5,11 @@ module Twitter
class Relationship < Twitter::Base

def source
@source ||= Twitter::User.new(@attributes['source']) unless @attributes['source'].nil?
@source ||= Twitter::User.new(@attrs['source']) unless @attrs['source'].nil?
end

def target
@target ||= Twitter::User.new(@attributes['target']) unless @attributes['target'].nil?
@target ||= Twitter::User.new(@attrs['target']) unless @attrs['target'].nil?
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/settings.rb
Expand Up @@ -9,7 +9,7 @@ class Settings < Twitter::Base
alias :protected? :protected

def trend_location
@trend_location ||= Twitter::Place.new(@attributes['trend_location'].first) unless @attributes['trend_location'].nil? || @attributes['trend_location'].empty?
@trend_location ||= Twitter::Place.new(@attrs['trend_location'].first) unless @attrs['trend_location'].nil? || @attrs['trend_location'].empty?
end

end
Expand Down
24 changes: 12 additions & 12 deletions lib/twitter/status.rb
Expand Up @@ -11,7 +11,7 @@ module Twitter
class Status < Twitter::Base
include Twitter::Creatable
lazy_attr_reader :favorited, :from_user, :from_user_id, :id,
:in_reply_to_screen_name, :in_reply_to_attributes_id, :in_reply_to_user_id,
:in_reply_to_screen_name, :in_reply_to_attrs_id, :in_reply_to_user_id,
:iso_language_code, :profile_image_url, :retweet_count, :retweeted,
:source, :text, :to_user, :to_user_id, :truncated
alias :favorited? :favorited
Expand All @@ -23,43 +23,43 @@ def ==(other)
end

def expanded_urls
@expanded_urls ||= Array(@attributes['entities']['urls']).map do |url|
@expanded_urls ||= Array(@attrs['entities']['urls']).map do |url|
url['expanded_url']
end unless @attributes['entities'].nil?
end unless @attrs['entities'].nil?
end

def geo
@geo ||= Twitter::GeoFactory.new(@attributes['geo']) unless @attributes['geo'].nil?
@geo ||= Twitter::GeoFactory.new(@attrs['geo']) unless @attrs['geo'].nil?
end

def hashtags
@hashtags ||= Twitter::Extractor.extract_hashtags(@attributes['text']) unless @attributes['text'].nil?
@hashtags ||= Twitter::Extractor.extract_hashtags(@attrs['text']) unless @attrs['text'].nil?
end

def media
@media ||= Array(@attributes['entities']['media']).map do |media|
@media ||= Array(@attrs['entities']['media']).map do |media|
Twitter::MediaFactory.new(media)
end unless @attributes['entities'].nil?
end unless @attrs['entities'].nil?
end

def metadata
@metadata ||= Twitter::Metadata.new(@attributes['metadata']) unless @attributes['metadata'].nil?
@metadata ||= Twitter::Metadata.new(@attrs['metadata']) unless @attrs['metadata'].nil?
end

def place
@place ||= Twitter::Place.new(@attributes['place']) unless @attributes['place'].nil?
@place ||= Twitter::Place.new(@attrs['place']) unless @attrs['place'].nil?
end

def urls
@urls ||= Twitter::Extractor.extract_urls(@attributes['text']) unless @attributes['text'].nil?
@urls ||= Twitter::Extractor.extract_urls(@attrs['text']) unless @attrs['text'].nil?
end

def user
@user ||= Twitter::User.new(@attributes['user'].merge('status' => self.to_hash.delete_if{|key, value| key == 'user'})) unless @attributes['user'].nil?
@user ||= Twitter::User.new(@attrs['user'].merge('status' => self.to_hash.delete_if{|key, value| key == 'user'})) unless @attrs['user'].nil?
end

def user_mentions
@user_mentions ||= Twitter::Extractor.extract_mentioned_screen_names(@attributes['text']) unless @attributes['text'].nil?
@user_mentions ||= Twitter::Extractor.extract_mentioned_screen_names(@attrs['text']) unless @attrs['text'].nil?
end
alias :mentions :user_mentions

Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/suggestion.rb
Expand Up @@ -10,7 +10,7 @@ def ==(other)
end

def users
@users = Array(@attributes['users']).map do |user|
@users = Array(@attrs['users']).map do |user|
Twitter::User.new(user)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/user.rb
Expand Up @@ -54,7 +54,7 @@ def ==(other)
end

def status
@status ||= Twitter::Status.new(@attributes['status'].merge('user' => self.to_hash.delete_if{|key, value| key == 'status'})) unless @attributes['status'].nil?
@status ||= Twitter::Status.new(@attrs['status'].merge('user' => self.to_hash.delete_if{|key, value| key == 'status'})) unless @attrs['status'].nil?
end

end
Expand Down

0 comments on commit 918aca1

Please sign in to comment.