Class: Proscenium::UI::Breadcrumbs::ComputedElement
- Defined in:
- lib/proscenium/ui/breadcrumbs/computed_element.rb
Instance Method Summary collapse
-
#initialize(element, context) ⇒ ComputedElement
constructor
A new instance of ComputedElement.
-
#name ⇒ String
If name is a Symbol of a controller method, that method is called.
-
#path ⇒ String
If path is a Symbol of a controller method, that method is called.
Constructor Details
#initialize(element, context) ⇒ ComputedElement
Returns a new instance of ComputedElement.
5 6 7 8 |
# File 'lib/proscenium/ui/breadcrumbs/computed_element.rb', line 5 def initialize(element, context) @element = element @context = context end |
Instance Method Details
#name ⇒ String
If name is a Symbol of a controller method, that method is called. If name is a Symbol of a controller instance variable, that variable is returned. If name is a Proc, it is executed in the context of the controller instance.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/proscenium/ui/breadcrumbs/computed_element.rb', line 15 def name @name ||= case name = @element.name when Symbol if name.to_s.starts_with?('@') name = get_instance_variable(name) name.respond_to?(:for_breadcrumb) ? name. : name.to_s else res = @context.controller.send(name) res.try(:for_breadcrumb) || res.to_s end when Proc @context.controller.instance_exec(&name) else name.respond_to?(:for_breadcrumb) ? name. : name.to_s end end |
#path ⇒ String
If path is a Symbol of a controller method, that method is called. If path is a Symbol of a controller instance variable, that variable is returned. If path is an Array, each element is processed as above. If path is a Proc, it is executed in the context of the controller instance.
No matter what, the result is always passed to ‘url_for` before being returned.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/proscenium/ui/breadcrumbs/computed_element.rb', line 40 def path @path ||= unless @element.path.nil? case path = @element.path when Array path.map! { |x| x.to_s.starts_with?('@') ? get_instance_variable(x) : x } when Symbol if path.to_s.starts_with?('@') path = get_instance_variable(path) elsif @context.controller.respond_to?(path, true) path = @context.controller.send(path) end when Proc path = @context.controller.instance_exec(&path) end @context.url_for path end end |