Class: Para::Breadcrumbs::Breadcrumb
- Inherits:
-
Object
- Object
- Para::Breadcrumbs::Breadcrumb
- Includes:
- ActionDispatch::Routing::PolymorphicRoutes, Helpers::ResourceName
- Defined in:
- lib/para/breadcrumbs/breadcrumb.rb
Instance Attribute Summary collapse
-
#_path ⇒ Object
readonly
Returns the value of attribute _path.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#resource_or_identifier ⇒ Object
readonly
Returns the value of attribute resource_or_identifier.
Instance Method Summary collapse
- #active?(request) ⇒ Boolean
-
#initialize(resource_or_identifier, path, controller, *options) ⇒ Breadcrumb
constructor
A new instance of Breadcrumb.
-
#path ⇒ Object
Allow lazy evaluation of routes to define breadcrumbs before being able to access request or routes.
- #title ⇒ Object
Methods included from Helpers::ResourceName
Constructor Details
#initialize(resource_or_identifier, path, controller, *options) ⇒ Breadcrumb
Returns a new instance of Breadcrumb.
9 10 11 12 13 14 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 9 def initialize(resource_or_identifier, path, controller, *) @resource_or_identifier = resource_or_identifier @_path = path @controller = controller @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (private)
Allow #polymorphic_path to work by delegating missing methods ending with _path or _url to be tried on url_helpers
77 78 79 80 81 82 83 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 77 def method_missing(method_name, *args, &block) if path_method?(method_name) Rails.application.routes.url_helpers.try(method_name, *args) || super else super end end |
Instance Attribute Details
#_path ⇒ Object (readonly)
Returns the value of attribute _path.
7 8 9 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 7 def _path @_path end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
7 8 9 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 7 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 7 def @options end |
#resource_or_identifier ⇒ Object (readonly)
Returns the value of attribute resource_or_identifier.
7 8 9 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 7 def resource_or_identifier @resource_or_identifier end |
Instance Method Details
#active?(request) ⇒ Boolean
43 44 45 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 43 def active?(request) path == request.path || path == '#' end |
#path ⇒ Object
Allow lazy evaluation of routes to define breadcrumbs before being able to access request or routes
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 29 def path @path ||= if _path.is_a?(Symbol) find_route_for(_path, *) elsif _path _path else begin polymorphic_path(resource_or_identifier) rescue '#' end end end |
#title ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/para/breadcrumbs/breadcrumb.rb', line 16 def title @title ||= if resource_or_identifier.is_a?(Symbol) translate(resource_or_identifier) elsif resource_or_identifier.is_a?(ActiveRecord::Base) resource_name(resource_or_identifier) else resource_or_identifier end end |