Class: Tramway::BaseDecorator
Overview
Provides decorate function for Tramway projects
Constant Summary
Helpers::ViewsHelper::FORM_SIZES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
association, associations
render
component
#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_chat, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title
#tramway_decorate
included
collection?, decorate_collection
Constructor Details
Returns a new instance of BaseDecorator.
25
26
27
|
# File 'lib/tramway/base_decorator.rb', line 25
def initialize(object)
@object = object
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/tramway/base_decorator.rb', line 99
def method_missing(method_name, *, &)
url_helpers = Rails.application.routes.url_helpers
if method_name.to_s.end_with?('_path', '_url')
return url_helpers.public_send(method_name, *, &) if url_helpers.respond_to?(method_name)
raise NoMethodError, "undefined method `#{method_name}` for #{self}" unless respond_to_missing?(method_name)
end
super
end
|
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
23
24
25
|
# File 'lib/tramway/base_decorator.rb', line 23
def object
@object
end
|
#view_context ⇒ Object
Returns the value of attribute view_context.
23
24
25
|
# File 'lib/tramway/base_decorator.rb', line 23
def view_context
@view_context
end
|
Class Method Details
.decorate(object_or_array) ⇒ Object
.delegate_attributes(*args) ⇒ Object
52
53
54
55
56
|
# File 'lib/tramway/base_decorator.rb', line 52
def delegate_attributes(*args)
args.each do |attribute|
delegate attribute, to: :object
end
end
|
.index_attributes ⇒ Object
58
59
60
|
# File 'lib/tramway/base_decorator.rb', line 58
def index_attributes
[]
end
|
62
63
64
|
# File 'lib/tramway/base_decorator.rb', line 62
def
nil
end
|
66
67
68
69
70
71
72
73
74
|
# File 'lib/tramway/base_decorator.rb', line 66
def (entity: nil, model_class: nil)
= index_attributes.map do |attribute|
(model_class || entity.model_class).human_attribute_name(attribute)
end
+= ['Actions'] if entity&.page(:update).present? || entity&.page(:destroy).present?
end
|
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
112
113
114
|
# File 'lib/tramway/base_decorator.rb', line 112
def respond_to_missing?(method_name, include_private = false)
method_name.to_s.end_with?('_path', '_url') || super
end
|
#show_associations ⇒ Object
91
92
93
|
# File 'lib/tramway/base_decorator.rb', line 91
def show_associations
[]
end
|
#show_attributes ⇒ Object
87
88
89
|
# File 'lib/tramway/base_decorator.rb', line 87
def show_attributes
[]
end
|
95
96
97
|
# File 'lib/tramway/base_decorator.rb', line 95
def
nil
end
|
#show_path ⇒ Object
85
|
# File 'lib/tramway/base_decorator.rb', line 85
def show_path = nil
|
#to_partial_path ⇒ Object
79
80
81
82
83
|
# File 'lib/tramway/base_decorator.rb', line 79
def to_partial_path
underscored_class_name = object.class.name.underscore
"#{underscored_class_name.pluralize}/#{underscored_class_name}"
end
|
#with(view_context:) ⇒ Object
29
30
31
32
33
|
# File 'lib/tramway/base_decorator.rb', line 29
def with(view_context:)
@view_context = view_context
self
end
|