Module: Draper::Decoratable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Equality
- Defined in:
- lib/draper/decoratable.rb,
lib/draper/decoratable/equality.rb,
lib/draper/decoratable/collection_proxy.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, CollectionProxy, 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.
35 36 37 |
# File 'lib/draper/decoratable.rb', line 35 def applied_decorators [] end |
#decorate(options = {}) ⇒ Object
Decorates the object using the inferred #decorator_class.
19 20 21 |
# File 'lib/draper/decoratable.rb', line 19 def decorate( = {}) decorator_class.decorate(self, ) end |
#decorated? ⇒ false
Checks if this object is decorated.
48 49 50 |
# File 'lib/draper/decoratable.rb', line 48 def decorated? false end |
#decorated_with?(decorator_class) ⇒ false
Checks if a given decorator has been applied to the object.
41 42 43 |
# File 'lib/draper/decoratable.rb', line 41 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
).
24 25 26 |
# File 'lib/draper/decoratable.rb', line 24 def decorator_class self.class.decorator_class end |
#decorator_class? ⇒ Boolean
28 29 30 |
# File 'lib/draper/decoratable.rb', line 28 def decorator_class? self.class.decorator_class? end |