Module: Draper::Decoratable

Extended by:
ActiveSupport::Concern
Includes:
Equality
Defined in:
lib/draper/decoratable.rb,
lib/draper/decoratable/equality.rb

Overview

Provides shortcuts to decorate objects directly, so you can do @product.decorate instead of ProductDecorator.new(@product).

This module is included by default into ActiveRecord::Base and Mongoid::Document, but you're using another ORM, or want to decorate plain old Ruby objects, you can include it manually.

Defined Under Namespace

Modules: ClassMethods, Equality

Instance Method Summary collapse

Methods included from Equality

#==, test

Instance Method Details

#applied_decoratorsArray<Class>

The list of decorators that have been applied to the object.

Returns:

  • (Array<Class>)

    []



33
34
35
# File 'lib/draper/decoratable.rb', line 33

def applied_decorators
  []
end

#decorate(options = {}) ⇒ Object

Decorates the object using the inferred #decorator_class.

Parameters:



17
18
19
# File 'lib/draper/decoratable.rb', line 17

def decorate(options = {})
  decorator_class.decorate(self, options)
end

#decorated?false

Checks if this object is decorated.

Returns:

  • (false)


46
47
48
# File 'lib/draper/decoratable.rb', line 46

def decorated?
  false
end

#decorated_with?(decorator_class) ⇒ false

Checks if a given decorator has been applied to the object.

Parameters:

  • decorator_class (Class)

Returns:

  • (false)


39
40
41
# File 'lib/draper/decoratable.rb', line 39

def decorated_with?(decorator_class)
  false
end

#decorator_classClass

Infers the decorator class to be used by #decorate (e.g. Product maps to ProductDecorator).

Returns:

  • (Class)

    the inferred decorator class.



22
23
24
# File 'lib/draper/decoratable.rb', line 22

def decorator_class
  self.class.decorator_class
end

#decorator_class?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/draper/decoratable.rb', line 26

def decorator_class?
  self.class.decorator_class?
end