diff --git a/lib/draper/model_support.rb b/lib/draper/model_support.rb index 56eecd0..5bbb78a 100644 --- a/lib/draper/model_support.rb +++ b/lib/draper/model_support.rb @@ -2,16 +2,24 @@ module Draper::ModelSupport extend ActiveSupport::Concern def decorator(options = {}) - @decorator ||= "#{self.class.name}Decorator".constantize.decorate(self, options.merge(:infer => false)) + @decorator ||= decorator_class.decorate(self, options.merge(:infer => false)) block_given? ? yield(@decorator) : @decorator end + def decorator_class + "#{self.class.name}Decorator".constantize + end + alias :decorate :decorator module ClassMethods def decorate(options = {}) - decorator_proxy = "#{model_name}Decorator".constantize.decorate(self.scoped, options) + decorator_proxy = decorator_class.decorate(self.scoped, options) block_given? ? yield(decorator_proxy) : decorator_proxy end + + def decorator_class + "#{model_name}Decorator".constantize + end end -end +end \ No newline at end of file