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:
commit
d5972640ab
1 changed files with 11 additions and 3 deletions
|
@ -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
|
Loading…
Reference in a new issue