1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge pull request #271 from cmer/master

Added `decorator_class` class and instance methods
This commit is contained in:
Steve Klabnik 2012-09-08 08:27:17 -07:00
commit d5972640ab

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