Move Equality module up to the top level
This commit is contained in:
parent
57a514133b
commit
7de7e90e78
|
@ -1,4 +1,4 @@
|
|||
require 'draper/decoratable/equality'
|
||||
require 'draper/equality'
|
||||
|
||||
module Draper
|
||||
# Provides shortcuts to decorate objects directly, so you can do
|
||||
|
@ -9,7 +9,7 @@ module Draper
|
|||
# plain old Ruby objects, you can include it manually.
|
||||
module Decoratable
|
||||
extend ActiveSupport::Concern
|
||||
include Draper::Decoratable::Equality
|
||||
include Draper::Equality
|
||||
|
||||
# Decorates the object using the inferred {#decorator_class}.
|
||||
# @param [Hash] options
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
module Draper
|
||||
module Decoratable
|
||||
module Equality
|
||||
# Compares self with a possibly-decorated object.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def ==(other)
|
||||
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?(:object) && test(object, other.object)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -170,7 +170,7 @@ module Draper
|
|||
#
|
||||
# @return [Boolean]
|
||||
def ==(other)
|
||||
Draper::Decoratable::Equality.test(object, other)
|
||||
Draper::Equality.test(object, other)
|
||||
end
|
||||
|
||||
# Delegates equality to :== as expected
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
module Draper
|
||||
module Equality
|
||||
# Compares self with a possibly-decorated object.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def ==(other)
|
||||
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?(:object) && test(object, other.object)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require 'support/shared_examples/decoratable_equality'
|
||||
require 'support/shared_examples/equality'
|
||||
|
||||
module Draper
|
||||
describe Decoratable do
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
require 'support/shared_examples/decoratable_equality'
|
||||
require 'support/shared_examples/equality'
|
||||
|
||||
module Draper
|
||||
describe Decoratable::Equality do
|
||||
describe Equality do
|
||||
describe "#==" do
|
||||
it_behaves_like "decoration-aware #==", Object.new.extend(Decoratable::Equality)
|
||||
it_behaves_like "decoration-aware #==", Object.new.extend(Equality)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue