Class: Tramway::BaseDecorator
- Inherits:
-
Object
- Object
- Tramway::BaseDecorator
- Extended by:
- Decorators::AssociationClassMethods
- Includes:
- Decorators::CollectionDecorators, DuckTyping::ActiveRecordCompatibility, Helpers::DecorateHelper, Utils::Render
- Defined in:
- lib/tramway/base_decorator.rb
Overview
Provides decorate function for Tramway projects
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
-
.decorate(object_or_array) ⇒ Object
:reek:NilCheck { enabled: false } because checking for nil is not a type-checking issue but business logic.
- .delegate_attributes(*args) ⇒ Object
- .list_attributes ⇒ Object
Instance Method Summary collapse
-
#initialize(object) ⇒ BaseDecorator
constructor
A new instance of BaseDecorator.
- #show_path ⇒ Object
- #to_partial_path ⇒ Object
Methods included from Decorators::AssociationClassMethods
Methods included from Helpers::DecorateHelper
Methods included from DuckTyping::ActiveRecordCompatibility
Methods included from Utils::Render
Methods included from Decorators::CollectionDecorators
collection?, decorate_collection
Constructor Details
#initialize(object) ⇒ BaseDecorator
Returns a new instance of BaseDecorator.
21 22 23 |
# File 'lib/tramway/base_decorator.rb', line 21 def initialize(object) @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
19 20 21 |
# File 'lib/tramway/base_decorator.rb', line 19 def object @object end |
Class Method Details
.decorate(object_or_array) ⇒ Object
:reek:NilCheck { enabled: false } because checking for nil is not a type-checking issue but business logic
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tramway/base_decorator.rb', line 27 def decorate(object_or_array) return if object_or_array.nil? if Tramway::Decorators::CollectionDecorators.collection?(object_or_array) Tramway::Decorators::CollectionDecorators.decorate_collection( collection: object_or_array, decorator: self ) else new(object_or_array) end end |
.delegate_attributes(*args) ⇒ Object
40 41 42 43 44 |
# File 'lib/tramway/base_decorator.rb', line 40 def delegate_attributes(*args) args.each do |attribute| delegate attribute, to: :object end end |
.list_attributes ⇒ Object
46 47 48 |
# File 'lib/tramway/base_decorator.rb', line 46 def list_attributes [] end |
Instance Method Details
#show_path ⇒ Object
59 |
# File 'lib/tramway/base_decorator.rb', line 59 def show_path = nil |
#to_partial_path ⇒ Object
53 54 55 56 57 |
# File 'lib/tramway/base_decorator.rb', line 53 def to_partial_path underscored_class_name = object.class.name.underscore "#{underscored_class_name.pluralize}/#{underscored_class_name}" end |