lib/draper/decorator.rb in draper-3.0.0.pre1 vs lib/draper/decorator.rb in draper-3.0.0

- old
+ new

@@ -8,12 +8,10 @@ include ActiveModel::Serializers::Xml # @return the object being decorated. attr_reader :object alias_method :model, :object - alias_method :source, :object # TODO: deprecate this - alias_method :to_source, :object # TODO: deprecate this # @return [Hash] extra data to be used in user-defined methods. attr_accessor :context # Wraps an object in a new instance of the decorator. @@ -70,19 +68,14 @@ end # Checks whether this decorator class has a corresponding {object_class}. def self.object_class? object_class - rescue Draper::UninferrableSourceError + rescue Draper::UninferrableObjectError false end - class << self # TODO deprecate this - alias_method :source_class, :object_class - alias_method :source_class?, :object_class? - end - # Automatically decorates ActiveRecord finder methods, so that you can use # `ProductDecorator.find(id)` instead of # `ProductDecorator.decorate(Product.find(id))`. # # Finder methods are applied to the {object_class}. @@ -180,11 +173,11 @@ self == other end # Returns a unique hash for a decorated object based on # the decorator class and the object being decorated. - # + # # @return [Fixnum] def hash self.class.hash ^ object.hash end @@ -228,12 +221,11 @@ # @return [Class] the class created by {decorate_collection}. def self.collection_decorator_class name = collection_decorator_name name.constantize - rescue NameError => error - raise if name && !error.missing_name?(name) + rescue NameError Draper::CollectionDecorator end private @@ -254,10 +246,10 @@ def self.inferred_object_class name = object_class_name name.constantize rescue NameError => error raise if name && !error.missing_name?(name) - raise Draper::UninferrableSourceError.new(self) + raise Draper::UninferrableObjectError.new(self) end def self.collection_decorator_name plural = object_class_name.pluralize raise NameError if plural == object_class_name