Class: Insight::Panel

Inherits:
Object
  • Object
show all
Includes:
ERB::Util, Database::RequestDataClient, Instrumentation::Client, Logging, Render
Defined in:
lib/insight/panel.rb

Overview

Panels are also Rack middleware

Direct Known Subclasses

ActiveRecordPanel, CachePanel, LogPanel, MemoryPanel, RailsInfoPanel, RedisPanel, RequestVariablesPanel, SQLPanel, SpeedTracer::Panel, TemplatesPanel, TimerPanel

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Instrumentation::Client

#after_detect, #before_detect, #probe, #request_finish, #request_start

Methods included from Logging

logger

Methods included from Database::RequestDataClient

#key_sql_template, #retrieve, #store, #table_length, #table_setup

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

- (Panel) initialize(app)

A new instance of Panel



65
66
67
68
69
70
71
72
# File 'lib/insight/panel.rb', line 65

def initialize(app)
  if panel_app
    #XXX use mappings
    @app = Rack::Cascade.new([panel_app, app])
  else
    @app = app
  end
end

Instance Attribute Details

- (Object) request (readonly)

Returns the value of attribute request



16
17
18
# File 'lib/insight/panel.rb', line 16

def request
  @request
end

Class Method Details

+ (Object) current_panel_file



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/insight/panel.rb', line 37

def current_panel_file
  return Thread::current['panel_file'] ||
    begin
      file_name = nil
      caller.each do |line|
        md = %r{^[^:]*insight/panels/([^:]*)\.rb:}.match line
        unless md.nil?
          file_name = md[1]
        end
      end
      file_name
    end
end

+ (Object) excluded(klass = nil)



59
60
61
# File 'lib/insight/panel.rb', line 59

def excluded(klass = nil)
  Panel::panel_exclusion << klass || self
end

+ (Object) file_index



19
20
21
22
23
# File 'lib/insight/panel.rb', line 19

def file_index
  return @file_index ||= Hash.new do |h,k|
    h[k] = []
  end
end

+ (Object) from_file(rel_path)



29
30
31
32
33
34
35
# File 'lib/insight/panel.rb', line 29

def from_file(rel_path)
  old_rel, Thread::current['panel_file'] = Thread::current['panel_file'], rel_path
  require File::join('insight', 'panels', rel_path)
  return (file_index[rel_path] - panel_exclusion)
ensure
  Thread::current['panel_file'] = old_rel
end

+ (Object) inherited(sub)



51
52
53
54
55
56
57
# File 'lib/insight/panel.rb', line 51

def inherited(sub)
  if filename = current_panel_file
    Panel::file_index[current_panel_file] << sub
  else
    warn "Insight::Panel inherited by #{sub.name} outside of an insight/panels/* file.  Discarded"
  end
end

+ (Object) panel_exclusion



25
26
27
# File 'lib/insight/panel.rb', line 25

def panel_exclusion
  return @panel_exclusion ||= []
end

+ (Object) panel_mappings



90
91
92
# File 'lib/insight/panel.rb', line 90

def self.panel_mappings
  {}
end

Instance Method Details

- (Object) after(env, status, headers, body)



113
114
# File 'lib/insight/panel.rb', line 113

def after(env, status, headers, body)
end

- (Object) before(env)



110
111
# File 'lib/insight/panel.rb', line 110

def before(env)
end

- (Object) call(env)



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/insight/panel.rb', line 74

def call(env)
  @env = env
  logger.debug{ "Before call: #{self.name}" }
  before(env)
  status, headers, body = @app.call(env)
  @request = Rack::Request.new(env)
  logger.debug{ "After call: #{self.name}" }
  after(env, status, headers, body)
  env["insight.panels"] << self
  return [status, headers, body]
end

- (Object) content_for_request(number)



106
107
108
# File 'lib/insight/panel.rb', line 106

def content_for_request(number)
  content rescue "" #XXX: no panel should need this
end

- (Boolean) has_content?

Returns:

  • (Boolean)


94
95
96
# File 'lib/insight/panel.rb', line 94

def has_content?
  true
end

- (Object) heading_for_request(number)



102
103
104
# File 'lib/insight/panel.rb', line 102

def heading_for_request(number)
  heading rescue "xxx" #XXX: no panel should need this
end

- (Object) name



98
99
100
# File 'lib/insight/panel.rb', line 98

def name
  "Unnamed panel: #{self.class.name}" #for shame
end

- (Object) panel_app



86
87
88
# File 'lib/insight/panel.rb', line 86

def panel_app
  nil
end

- (Object) render(template)



116
117
# File 'lib/insight/panel.rb', line 116

def render(template)
end