class Peek::Views::View

Public Class Methods

new(options = {}) click to toggle source
# File lib/peek/views/view.rb, line 4
def initialize(options = {})
  @options = options

  parse_options
  setup_subscribers
end

Public Instance Methods

context() click to toggle source

Additional context for any view to render tooltips for.

Returns Hash.

# File lib/peek/views/view.rb, line 75
def context
  {}
end
context?() click to toggle source
# File lib/peek/views/view.rb, line 79
def context?
  context.any?
end
context_id() click to toggle source

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
defer_key()
Alias for: key
dom_id() click to toggle source

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
enabled?() click to toggle source

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
key() click to toggle source

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
Also aliased as: defer_key
parse_options() click to toggle source

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
partial_path() click to toggle source

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
results() click to toggle source

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
results?() click to toggle source
# File lib/peek/views/view.rb, line 91
def results?
  results.any?
end
subscribe(*args) { |name, start, finish, id, payload| ... } click to toggle source
# 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

after_request() { |name, start, finish, id, payload| ... } click to toggle source

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
before_request() { |name, start, finish, id, payload| ... } click to toggle source

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
setup_subscribers() click to toggle source
# File lib/peek/views/view.rb, line 103
def setup_subscribers
  # pass
end