Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup #459

  • Loading branch information...
commit f1f9087b02dab05af7393f2e791aaabd745ac5f0 1 parent 9e9baa7
@sferik authored
View
32 lib/twitter/base.rb
@@ -51,30 +51,22 @@ def uri_attr_reader(*attrs)
index = array.index("uri")
array[index] = "url"
url_key = array.join("_").to_sym
- if uri_key == :display_uri
- define_display_uri_method(uri_key, url_key)
- else
- define_uri_method(uri_key, url_key)
- end
- define_predicate_method(uri_key, url_key)
+ define_uri_method(uri_key, url_key)
alias_method(url_key, uri_key)
- alias_method("#{url_key}?", "#{uri_key}?")
+ define_predicate_method(uri_key, url_key)
+ alias_method(:"#{url_key}?", :"#{uri_key}?")
end
end
- private
-
- # Dynamically define a method for a display URI
- #
- # @param key1 [Symbol]
- # @param key2 [Symbol]
- def define_display_uri_method(key1, key2)
- define_method(key1) do
- @attrs[key2] if @attrs[key2]
- end
- memoize(key1)
+ def display_uri_attr_reader
+ define_attribute_method(:display_url)
+ alias_method(:display_uri, :display_url)
+ define_predicate_method(:display_uri, :display_url)
+ alias_method(:display_url?, :display_uri?)
end
+ private
+
# Dynamically define a method for a URI
#
# @param key1 [Symbol]
@@ -114,7 +106,7 @@ def define_predicate_method(key1, key2=key1)
define_method(:"#{key1}?") do
!!@attrs[key2]
end
- memoize key1
+ memoize(:"#{key1}?")
end
end
@@ -138,7 +130,7 @@ def [](method)
private
- def attrs_for_object(key1, key2)
+ def attrs_for_object(key1, key2=nil)
if key2.nil?
@attrs[key1]
else
View
3  lib/twitter/entity/uri.rb
@@ -3,7 +3,8 @@
module Twitter
class Entity
class URI < Twitter::Entity
- uri_attr_reader :display_uri, :expanded_uri, :uri
+ display_uri_attr_reader
+ uri_attr_reader :expanded_uri, :uri
end
Uri = URI
View
3  lib/twitter/media/photo.rb
@@ -4,7 +4,8 @@ module Twitter
module Media
class Photo < Twitter::Identity
attr_reader :indices
- uri_attr_reader :display_uri, :expanded_uri, :media_uri, :media_uri_https, :uri
+ display_uri_attr_reader
+ uri_attr_reader :expanded_uri, :media_uri, :media_uri_https, :uri
# Returns an array of photo sizes
#
View
14 spec/twitter/entity/uri_spec.rb
@@ -1,19 +1,13 @@
-# encoding: utf-8
-
+# coding: utf-8
require 'helper'
describe Twitter::Entity::URI do
describe "#display_uri" do
it "returns a String when the display_url is set" do
- uri = Twitter::Entity::URI.new(:display_url => "https://github.com/sferik")
- expect(uri.display_uri).to be_a String
- expect(uri.display_uri.to_s).to eq("https://github.com/sferik")
- end
- it "returns a String when the display_url is set to a truncated version" do
- uri = Twitter::Entity::URI.new(:display_url => "gawker.com/louis-c-k-s-ex…")
+ uri = Twitter::Entity::URI.new(:display_url => "example.com/expanded…")
expect(uri.display_uri).to be_a String
- expect(uri.display_uri.to_s).to eq("gawker.com/louis-c-k-s-ex")
+ expect(uri.display_uri).to eq("example.com/expanded")
end
it "returns nil when the display_url is not set" do
uri = Twitter::Entity::URI.new
@@ -23,7 +17,7 @@
describe "#display_uri?" do
it "returns true when the display_url is set" do
- uri = Twitter::Entity::URI.new(:display_url => "https://github.com/sferik")
+ uri = Twitter::Entity::URI.new(:display_url => "example.com/expanded…")
expect(uri.display_uri).to be_true
end
it "returns false when the display_url is not set" do
View
7 spec/twitter/media/photo_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'helper'
describe Twitter::Media::Photo do
@@ -34,9 +35,9 @@
describe "#display_uri" do
it "returns a String when the display_url is set" do
- photo = Twitter::Media::Photo.new(:id => 1, :display_url => "http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png")
+ photo = Twitter::Media::Photo.new(:id => 1, :display_url => "example.com/expanded…")
expect(photo.display_uri).to be_a String
- expect(photo.display_uri.to_s).to eq("http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png")
+ expect(photo.display_uri).to eq("example.com/expanded…")
end
it "returns nil when the display_url is not set" do
photo = Twitter::Media::Photo.new(:id => 1)
@@ -46,7 +47,7 @@
describe "#display_uri?" do
it "returns true when the display_url is set" do
- photo = Twitter::Media::Photo.new(:id => 1, :display_url => "http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png")
+ photo = Twitter::Media::Photo.new(:id => 1, :display_url => "example.com/expanded…")
expect(photo.display_uri).to be_true
end
it "returns false when the display_url is not set" do
View
7 spec/twitter/tweet_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require 'helper'
describe Twitter::Tweet do
@@ -67,7 +68,7 @@
{
:url => "http://example.com/t.co",
:expanded_url => "http://example.com/expanded",
- :display_url => "example.com/expanded",
+ :display_url => "example.com/expanded",
:indices => [10, 33],
}
]
@@ -290,7 +291,7 @@
{
:url => "http://example.com/t.co",
:expanded_url => "http://example.com/expanded",
- :display_url => "example.com/expanded",
+ :display_url => "example.com/expanded",
:indices => [10, 33],
}
]
@@ -299,7 +300,7 @@
expect(tweet.uris.first).to be_a Twitter::Entity::URI
expect(tweet.uris.first.indices).to eq([10, 33])
expect(tweet.uris.first.display_uri).to be_a String
- expect(tweet.uris.first.display_uri.to_s).to eq("example.com/expanded")
+ expect(tweet.uris.first.display_uri).to eq("example.com/expanded")
end
it "is empty when not set" do
tweet = Twitter::Tweet.new(:id => 28669546014)
View
4 spec/twitter/user_spec.rb
@@ -49,7 +49,7 @@
{
:url => "http://example.com/t.co",
:expanded_url => "http://example.com/expanded",
- :display_url => "example.com/expanded",
+ :display_url => "example.com/expanded",
:indices => [10, 33],
}
]
@@ -57,7 +57,7 @@
expect(user.description_uris).to be_an Array
expect(user.description_uris.first).to be_a Twitter::Entity::URI
expect(user.description_uris.first.indices).to eq([10, 33])
- expect(user.description_uris.first.display_uri.to_s).to eq("example.com/expanded")
+ expect(user.description_uris.first.display_uri).to eq("example.com/expanded")
end
it "is empty when not set" do
user = Twitter::User.new(:id => 7505382, :entities => {:description => {:urls => []}})
Please sign in to comment.
Something went wrong with that request. Please try again.