Skip to content

Commit

Permalink
Move Hash#except and Hash#except! into Twitter::Exceptable module
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 21, 2012
1 parent 2e8bfa3 commit 0a8591e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
1 change: 0 additions & 1 deletion lib/twitter/api/utils.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'twitter/core_ext/enumerable'
require 'twitter/core_ext/hash'
require 'twitter/core_ext/kernel'
require 'twitter/cursor'
require 'twitter/user'
Expand Down
20 changes: 0 additions & 20 deletions lib/twitter/core_ext/hash.rb

This file was deleted.

24 changes: 24 additions & 0 deletions lib/twitter/exceptable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Twitter
module Exceptable

# Return a hash that includes everything but the given keys.
#
# @param hash [Hash]
# @param key [Symbol]
# @return [Hash]
def except(hash, key)
except!(hash.dup, key)
end

# Replaces the hash without the given keys.
#
# @param hash [Hash]
# @param key [Symbol]
# @return [Hash]
def except!(hash, key)
hash.delete(key)
hash
end

end
end
5 changes: 3 additions & 2 deletions lib/twitter/tweet.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'twitter/core_ext/hash'
require 'twitter/creatable'
require 'twitter/entity/hashtag'
require 'twitter/entity/url'
require 'twitter/entity/user_mention'
require 'twitter/exceptable'
require 'twitter/geo_factory'
require 'twitter/identity'
require 'twitter/media_factory'
Expand All @@ -13,6 +13,7 @@
module Twitter
class Tweet < Twitter::Identity
include Twitter::Creatable
include Twitter::Exceptable
attr_reader :favorited, :favoriters, :from_user_id, :from_user_name,
:in_reply_to_screen_name, :in_reply_to_attrs_id, :in_reply_to_status_id,
:in_reply_to_user_id, :iso_language_code, :profile_image_url,
Expand Down Expand Up @@ -121,7 +122,7 @@ def urls

# @return [Twitter::User]
def user
@user ||= Twitter::User.fetch_or_new(@attrs.dup[:user].merge(:status => @attrs.except(:user))) if user?
@user ||= Twitter::User.fetch_or_new(@attrs.dup[:user].merge(:status => except(@attrs, :user))) if user?
end

# @note Must include entities in your request for this method to work
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter/user.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require 'twitter/basic_user'
require 'twitter/core_ext/hash'
require 'twitter/creatable'
require 'twitter/exceptable'
require 'twitter/tweet'

module Twitter
class User < Twitter::BasicUser
PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/
include Twitter::Creatable
include Twitter::Exceptable
attr_reader :connections, :contributors_enabled, :default_profile,
:default_profile_image, :description, :favourites_count,
:follow_request_sent, :followers_count, :friends_count, :geo_enabled,
Expand Down Expand Up @@ -93,7 +94,7 @@ def profile_image_url?

# @return [Twitter::Tweet]
def status
@status ||= Twitter::Tweet.fetch_or_new(@attrs.dup[:status].merge(:user => @attrs.except(:status))) if status?
@status ||= Twitter::Tweet.fetch_or_new(@attrs.dup[:status].merge(:user => except(@attrs, :status))) if status?
end

def status?
Expand Down

0 comments on commit 0a8591e

Please sign in to comment.