2011-08-08 02:07:40 +00:00
|
|
|
module Draper::ModelSupport
|
2012-03-27 19:47:27 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2011-11-10 01:02:23 +00:00
|
|
|
def decorator(options = {})
|
2011-11-10 03:31:48 +00:00
|
|
|
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self, options.merge(:infer => false))
|
2011-09-16 18:42:33 +00:00
|
|
|
block_given? ? yield(@decorator) : @decorator
|
2011-08-08 02:07:40 +00:00
|
|
|
end
|
2011-11-10 03:31:48 +00:00
|
|
|
|
2011-10-29 01:14:02 +00:00
|
|
|
alias :decorate :decorator
|
2011-10-28 12:07:03 +00:00
|
|
|
|
|
|
|
module ClassMethods
|
2011-11-10 01:02:23 +00:00
|
|
|
def decorate(options = {})
|
2012-01-26 20:07:18 +00:00
|
|
|
decorator_proxy = "#{model_name}Decorator".constantize.decorate(self.scoped, options)
|
|
|
|
block_given? ? yield(decorator_proxy) : decorator_proxy
|
2011-10-28 12:07:03 +00:00
|
|
|
end
|
|
|
|
end
|
2011-08-08 02:07:40 +00:00
|
|
|
end
|