module Draper::Decoratable::ClassMethods
Public Instance Methods
Source
# File lib/draper/decoratable.rb, line 89 def ===(other) super || (other.is_a?(Draper::Decorator) && super(other.object)) end
Compares with possibly-decorated objects.
@return [Boolean]
Calls superclass method
Source
# File lib/draper/decoratable.rb, line 59 def decorate(options = {}) decorator_class.decorate_collection(all, options.reverse_merge(with: nil)) end
Decorates a collection of objects. Used at the end of a scope chain.
@example
Product.popular.decorate
@param [Hash] options
see {Decorator.decorate_collection}.
Source
# File lib/draper/decoratable.rb, line 73 def decorator_class(called_on = self) prefix = respond_to?(:model_name) ? model_name : name decorator_name = "#{prefix}Decorator" decorator_name_constant = decorator_name.safe_constantize return decorator_name_constant unless decorator_name_constant.nil? if superclass.respond_to?(:decorator_class) superclass.decorator_class(called_on) else raise Draper::UninferrableDecoratorError.new(called_on) end end
Infers the decorator class to be used by {Decoratable#decorate} (e.g. ‘Product` maps to `ProductDecorator`).
@return [Class] the inferred decorator class.
Source
# File lib/draper/decoratable.rb, line 63 def decorator_class? decorator_class rescue Draper::UninferrableDecoratorError false end