lib/draper/decoratable.rb in draper-3.0.0 vs lib/draper/decoratable.rb in draper-3.0.1

- old
+ new

@@ -67,19 +67,19 @@ # Infers the decorator class to be used by {Decoratable#decorate} (e.g. # `Product` maps to `ProductDecorator`). # # @return [Class] the inferred decorator class. - def decorator_class + def decorator_class(called_on = self) prefix = respond_to?(:model_name) ? model_name : name decorator_name = "#{prefix}Decorator" - decorator_name.constantize - rescue NameError => error - raise unless error.missing_name?(decorator_name) + 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 + superclass.decorator_class(called_on) else - raise Draper::UninferrableDecoratorError.new(self) + raise Draper::UninferrableDecoratorError.new(called_on) end end # Compares with possibly-decorated objects. #