class Peek::Views::View
Public Class Methods
# File lib/peek/views/view.rb, line 4 def initialize(options = {}) @options = options parse_options setup_subscribers end
Public Instance Methods
Additional context for any view to render tooltips for.
Returns Hash.
# File lib/peek/views/view.rb, line 75 def context {} end
# File lib/peek/views/view.rb, line 79 def context? context.any? end
The context id that is derived from the classname.
Examples:
Peek::Views::PerformanceBar => "peek-context-performance-bar" Peek::Views::Resque => "peek-context-resque"
Returns String.
# File lib/peek/views/view.rb, line 61 def context_id "peek-context-#{key}" end
The wrapper ID for the individual view in the Peek
bar.
Returns String.
# File lib/peek/views/view.rb, line 68 def dom_id "peek-view-#{key}" end
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.
# File lib/peek/views/view.rb, line 24 def enabled? true end
The defer key that is derived from the classname.
Examples:
Peek::Views::PerformanceBar => "performance-bar" Peek::Views::Resque => "resque"
Returns String.
# File lib/peek/views/view.rb, line 48 def key self.class.to_s.split('::').last.underscore.gsub(/\_/, '-') end
Where any subclasses should pick and pull from @options to set any and all instance variables they like.
Returns nothing.
# File lib/peek/views/view.rb, line 15 def parse_options # pass end
The path to the partial that will be rendered to the Peek
bar.
Examples:
Peek::Views::PerformanceBar.partial_path => "peek/views/performance_bar" CustomResque.partial_path => "performance_bar"
Returns String.
# File lib/peek/views/view.rb, line 36 def partial_path self.class.to_s.underscore end
The data results that are inserted at the end of the request for use in deferred placeholders in the Peek
the bar.
Returns Hash.
# File lib/peek/views/view.rb, line 87 def results {} end
# File lib/peek/views/view.rb, line 91 def results? results.any? end
# File lib/peek/views/view.rb, line 95 def subscribe(*args) ActiveSupport::Notifications.subscribe(*args) do |name, start, finish, id, payload| yield name, start, finish, id, payload end end
Private Instance Methods
Helper method for subscribing to the event that is fired when requests are finished.
# File lib/peek/views/view.rb, line 117 def after_request subscribe 'process_action.action_controller' do |name, start, finish, id, payload| yield name, start, finish, id, payload end end
Helper method for subscribing to the event that is fired when new requests are made.
# File lib/peek/views/view.rb, line 109 def before_request subscribe 'start_processing.action_controller' do |name, start, finish, id, payload| yield name, start, finish, id, payload end end
# File lib/peek/views/view.rb, line 103 def setup_subscribers # pass end