lib/draper/decoratable.rb in draper-1.2.1 vs lib/draper/decoratable.rb in draper-1.3.0
- old
+ new
@@ -21,10 +21,14 @@
# (see ClassMethods#decorator_class)
def decorator_class
self.class.decorator_class
end
+ def decorator_class?
+ self.class.decorator_class?
+ end
+
# The list of decorators that have been applied to the object.
#
# @return [Array<Class>] `[]`
def applied_decorators
[]
@@ -52,9 +56,15 @@
# @param [Hash] options
# see {Decorator.decorate_collection}.
def decorate(options = {})
collection = Rails::VERSION::MAJOR >= 4 ? all : scoped
decorator_class.decorate_collection(collection, options.reverse_merge(with: nil))
+ end
+
+ def decorator_class?
+ decorator_class
+ rescue Draper::UninferrableDecoratorError
+ false
end
# Infers the decorator class to be used by {Decoratable#decorate} (e.g.
# `Product` maps to `ProductDecorator`).
#