lib/draper/decorator.rb in draper-3.1.0 vs lib/draper/decorator.rb in draper-4.0.0

- old
+ new

@@ -10,12 +10,13 @@ include ActiveModel::Serializers::JSON include ActiveModel::Serializers::Xml # @return the object being decorated. attr_reader :object - alias_method :model, :object + alias :model :object + # @return [Hash] extra data to be used in user-defined methods. attr_accessor :context # Wraps an object in a new instance of the decorator. # @@ -34,11 +35,11 @@ @context = options.fetch(:context, {}) handle_multiple_decoration(options) if object.instance_of?(self.class) end class << self - alias_method :decorate, :new + alias :decorate :new end # Automatically delegates instance methods to the source object. Class # methods will be delegated to the {object_class}, if it is set. # @@ -188,12 +189,13 @@ # # @param [Class] klass def kind_of?(klass) super || object.kind_of?(klass) end - alias_method :is_a?, :kind_of? + alias :is_a? :kind_of? + # Checks if `self.instance_of?(klass)` or `object.instance_of?(klass)` # # @param [Class] klass def instance_of?(klass) super || object.instance_of?(klass) @@ -223,11 +225,11 @@ singleton_class.delegate :model_name, to: :object_class # @return [Class] the class created by {decorate_collection}. def self.collection_decorator_class name = collection_decorator_name - name_constant = name && name.safe_constantize + name_constant = name&.safe_constantize name_constant || Draper::CollectionDecorator end private @@ -246,18 +248,18 @@ name.chomp("Decorator") end def self.inferred_object_class name = object_class_name - name_constant = name && name.safe_constantize + name_constant = name&.safe_constantize return name_constant unless name_constant.nil? raise Draper::UninferrableObjectError.new(self) end def self.collection_decorator_name singular = object_class_name - plural = singular && singular.pluralize + plural = singular&.pluralize "#{plural}Decorator" unless plural == singular end def handle_multiple_decoration(options)