1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Avoid using extend in Decorator#==

This commit is contained in:
Andrew Haines 2013-04-01 16:06:52 +01:00
parent 43359e0efc
commit 205a0d43b4
2 changed files with 16 additions and 4 deletions

View file

@ -5,9 +5,21 @@ module Draper
#
# @return [Boolean]
def ==(other)
super ||
super || Equality.test_for_decorator(self, other)
end
# Compares an object to a possibly-decorated object.
#
# @return [Boolean]
def self.test(object, other)
return object == other if object.is_a?(Decoratable)
object == other || test_for_decorator(object, other)
end
# @private
def self.test_for_decorator(object, other)
other.respond_to?(:decorated?) && other.decorated? &&
other.respond_to?(:source) && self == other.source
other.respond_to?(:source) && test(object, other.source)
end
end
end

View file

@ -163,7 +163,7 @@ module Draper
#
# @return [Boolean]
def ==(other)
source.extend(Draper::Decoratable::Equality) == other
Draper::Decoratable::Equality.test(source, other)
end
# Checks if `self.kind_of?(klass)` or `source.kind_of?(klass)`