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
-
#applied_decorators ⇒ Array<Class>
The list of decorators that have been applied to the object.
-
#decorate(options = {}) ⇒ Object
Decorates the object using the inferred #decorator_class.
-
#decorated? ⇒ false
Checks if this object is decorated.
-
#decorated_with?(decorator_class) ⇒ false
Checks if a given decorator has been applied to the object.
-
#decorator_class ⇒ Class
Infers the decorator class to be used by #decorate (e.g.
Product
maps toProductDecorator
). - #decorator_class? ⇒ Boolean
Methods included from Equality
Instance Method Details
#applied_decorators ⇒ Array<Class>
The list of decorators that have been applied to the object.
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.
17 18 19 |
# File 'lib/draper/decoratable.rb', line 17 def decorate( = {}) decorator_class.decorate(self, ) end |
#decorated? ⇒ false
Checks if this object is decorated.
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.
39 40 41 |
# File 'lib/draper/decoratable.rb', line 39 def decorated_with?(decorator_class) false end |
#decorator_class ⇒ Class
Infers the decorator class to be used by #decorate (e.g.
Product
maps to ProductDecorator
).
22 23 24 |
# File 'lib/draper/decoratable.rb', line 22 def decorator_class self.class.decorator_class end |
#decorator_class? ⇒ Boolean
26 27 28 |
# File 'lib/draper/decoratable.rb', line 26 def decorator_class? self.class.decorator_class? end |