Module: ActsAsDraperDecorated::InstanceMethods

Defined in:
lib/acts_as_draper_decorated.rb

Instance Method Summary collapse

Instance Method Details

#decorated(type = nil) ⇒ Object Also known as: d



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acts_as_draper_decorated.rb', line 15

def decorated type = nil
  type = type.to_s unless type.nil?
  if type.nil?
    return @decorated if @decorated
  else
    @decorated_types ||= {}
    return @decorated_types[type] if @decorated_types[type] 
  end
  klass = self.class
  while klass
    begin
      if type.nil?
        @decorated ||= (klass.name + 'Decorator').constantize.decorate(self) 
        return @decorated
      else
        return @decorated_types[type] ||= ("#{type.to_s.classify}#{klass.name}Decorator").constantize.decorate(self)
      end
    rescue
      klass = klass.superclass
    end
  end
end