Added `decorator_class` class and instance methods

This commit is contained in:
Carl Mercier 2012-09-07 16:05:15 -04:00
parent 044a6e6519
commit bda31289c0
1 changed files with 11 additions and 3 deletions

View File

@ -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