Class: Cmtool::Menu::ResourceLink
Overview
Resource link, indicates a link to standard resource. The first argument should
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from ElementBase
#controller_names, #engine_link?, #method_missing, #options
Constructor Details
#initialize(resource, options = {}) ⇒ ResourceLink
Returns a new instance of ResourceLink.
124
125
126
|
# File 'lib/cmtool/menu.rb', line 124
def initialize(resource, options = {})
@resource, @options = resource, options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Cmtool::Menu::ElementBase
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
123
124
125
|
# File 'lib/cmtool/menu.rb', line 123
def resource
@resource
end
|
Instance Method Details
#controller_name ⇒ Object
132
133
134
|
# File 'lib/cmtool/menu.rb', line 132
def controller_name
@resource.name.underscore.split('/').last.pluralize
end
|
#engine ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/cmtool/menu.rb', line 142
def engine
return @options[:engine] if @options[:engine].present?
base = @options[:scope].presence
base ||= @resource.name.split('::').first if @resource.name.index('::')
return Rails.application unless base
return base if base.is_a?(Rails::Engine)
if e = "#{base}::Engine".safe_constantize
return e
end
return Rails.application
end
|
#nested_controller_name ⇒ Object
153
154
155
156
157
158
159
|
# File 'lib/cmtool/menu.rb', line 153
def nested_controller_name
if @options[:scope].present?
"#{@options[:scope]}::#{@resource.name.split('::').last}".underscore.pluralize
else
@resource.name.underscore.pluralize
end
end
|
#path ⇒ Object
138
139
140
|
# File 'lib/cmtool/menu.rb', line 138
def path
engine.routes.url_helpers.url_for({controller: nested_controller_name, action: 'index', only_path: true}.merge(@options[:path] || {}))
end
|
#resource_link? ⇒ Boolean
128
129
130
|
# File 'lib/cmtool/menu.rb', line 128
def resource_link?
true
end
|
#title ⇒ Object
135
136
137
|
# File 'lib/cmtool/menu.rb', line 135
def title
@resource.model_name.human_plural
end
|