lib/draper/decorator.rb in draper-1.0.0 vs lib/draper/decorator.rb in draper-1.1.0

- old
+ new

@@ -1,12 +1,10 @@ -require 'active_support/core_ext/array/extract_options' - module Draper class Decorator include Draper::ViewHelpers extend Draper::Delegation - include ActiveModel::Serialization if defined?(ActiveModel::Serialization) + include ActiveModel::Serialization # @return the object being decorated. attr_reader :source alias_method :model, :source alias_method :to_source, :source @@ -25,11 +23,10 @@ # @option options [Hash] :context ({}) # extra data to be stored in the decorator and used in user-defined # methods. def initialize(source, options = {}) options.assert_valid_keys(:context) - source.to_a if source.respond_to?(:to_a) # forces evaluation of a lazy query from AR @source = source @context = options.fetch(:context, {}) handle_multiple_decoration(options) if source.instance_of?(self.class) end @@ -157,15 +154,15 @@ # @return [true] def decorated? true end - # Delegated to the source object. + # Compares the source with a possibly-decorated object. # # @return [Boolean] def ==(other) - source == (other.respond_to?(:source) ? other.source : other) + source.extend(Draper::Decoratable::Equality) == other end # Checks if `self.kind_of?(klass)` or `source.kind_of?(klass)` # # @param [Class] klass @@ -189,10 +186,10 @@ def to_model self end # ActiveModel compatibility - delegate :to_param, :to_partial_path + delegate :attributes, :to_param, :to_partial_path # ActiveModel compatibility singleton_class.delegate :model_name, to: :source_class # @return [Class] the class created by {decorate_collection}.