Class: Glimpse::Views::View
- Inherits:
-
Object
- Object
- Glimpse::Views::View
- Defined in:
- lib/glimpse/views/view.rb
Instance Method Summary collapse
-
#context ⇒ Object
Additional context for any view to render tooltips for.
- #context? ⇒ Boolean
-
#context_dom_id ⇒ Object
The context dom id that is derived from the classname.
-
#defer_key ⇒ Object
The defer key that is derived from the classname.
-
#dom_id ⇒ Object
The wrapper ID for the individual view in the Glimpse bar.
-
#enabled? ⇒ Boolean
Conditionally enable views based on any gathered data.
-
#initialize(options = {}) ⇒ View
constructor
A new instance of View.
-
#partial_path ⇒ Object
The path to the partial that will be rendered to the Glimpse bar.
-
#results ⇒ Object
The data results that are inserted at the end of the request for use in deferred placeholders in the Glimpse the bar.
- #results? ⇒ Boolean
- #subscribe(*args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ View
Returns a new instance of View.
4 5 6 7 8 |
# File 'lib/glimpse/views/view.rb', line 4 def initialize( = {}) @options = setup_subscribers end |
Instance Method Details
#context ⇒ Object
Additional context for any view to render tooltips for.
Returns Hash.
65 66 67 |
# File 'lib/glimpse/views/view.rb', line 65 def context {} end |
#context? ⇒ Boolean
69 70 71 |
# File 'lib/glimpse/views/view.rb', line 69 def context? context.any? end |
#context_dom_id ⇒ Object
51 52 53 |
# File 'lib/glimpse/views/view.rb', line 51 def context_dom_id "glimpse-context-#{defer_key}" end |
#defer_key ⇒ Object
39 40 41 |
# File 'lib/glimpse/views/view.rb', line 39 def defer_key self.class.to_s.split('::').last.underscore.gsub(/\_/, '-') end |
#dom_id ⇒ Object
The wrapper ID for the individual view in the Glimpse bar.
Returns String.
58 59 60 |
# File 'lib/glimpse/views/view.rb', line 58 def dom_id "glimpse-view-#{defer_key}" end |
#enabled? ⇒ Boolean
Conditionally enable views based on any gathered data. Helpful if you don’t want views to show up when they return 0 or are touched during the request.
Returns true.
15 16 17 |
# File 'lib/glimpse/views/view.rb', line 15 def enabled? true end |
#partial_path ⇒ Object
27 28 29 |
# File 'lib/glimpse/views/view.rb', line 27 def partial_path self.class.to_s.underscore end |
#results ⇒ Object
The data results that are inserted at the end of the request for use in deferred placeholders in the Glimpse the bar.
Returns Hash.
77 78 79 |
# File 'lib/glimpse/views/view.rb', line 77 def results {} end |
#results? ⇒ Boolean
81 82 83 |
# File 'lib/glimpse/views/view.rb', line 81 def results? results.any? end |
#subscribe(*args) ⇒ Object
85 86 87 88 89 |
# File 'lib/glimpse/views/view.rb', line 85 def subscribe(*args) ActiveSupport::Notifications.subscribe(*args) do |name, start, finish, id, payload| yield name, start, finish, id, payload end end |