Class: Tramway::BaseDecorator

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Decorators::AssociationClassMethods

association, associations

Methods included from Helpers::DecorateHelper

#tramway_decorate

Methods included from DuckTyping::ActiveRecordCompatibility

included

Methods included from Utils::Render

#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

#objectObject (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_attributesObject



46
47
48
# File 'lib/tramway/base_decorator.rb', line 46

def list_attributes
  []
end

Instance Method Details

#show_pathObject



59
# File 'lib/tramway/base_decorator.rb', line 59

def show_path = nil

#to_partial_pathObject



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