lib/twitter/base.rb in twitter-6.1.0 vs lib/twitter/base.rb in twitter-6.2.0
- old
+ new
@@ -11,11 +11,10 @@
include Twitter::Utils
# @return [Hash]
attr_reader :attrs
alias to_h attrs
alias to_hash to_h
- deprecate_alias :to_hsh, :to_hash
class << self
# Define methods that retrieve the value from attributes
#
# @param attrs [Array, Symbol]
@@ -27,11 +26,10 @@
end
def predicate_attr_reader(*attrs)
attrs.each do |attr|
define_predicate_method(attr)
- deprecate_attribute_method(attr)
end
end
# Define object methods from attributes
#
@@ -85,29 +83,17 @@
# @param key2 [Symbol]
def define_attribute_method(key1, klass = nil, key2 = nil)
define_method(key1) do
if attr_falsey_or_empty?(key1)
NullObject.new
- elsif klass.nil?
- @attrs[key1]
else
- attrs = attrs_for_object(key1, key2)
- Twitter.const_get(klass).new(attrs)
+ klass.nil? ? @attrs[key1] : Twitter.const_get(klass).new(attrs_for_object(key1, key2))
end
end
memoize(key1)
end
- # @param key [Symbol]
- def deprecate_attribute_method(key)
- define_method(key) do
- warn "#{Kernel.caller.first}: [DEPRECATION] ##{key} is deprecated. Use ##{key}? instead."
- @attrs[key]
- end
- memoize(key)
- end
-
# Dynamically define a predicate method for an attribute
#
# @param key1 [Symbol]
# @param key2 [Symbol]
def define_predicate_method(key1, key2 = key1)
@@ -137,10 +123,10 @@
end
private
def attr_falsey_or_empty?(key)
- @attrs[key].nil? || @attrs[key] == false || @attrs[key].respond_to?(:empty?) && @attrs[key].empty?
+ !@attrs[key] || @attrs[key].respond_to?(:empty?) && @attrs[key].empty?
end
def attrs_for_object(key1, key2 = nil)
if key2.nil?
@attrs[key1]