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

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

#initialize(app) ⇒ Panel

Returns 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

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

Class Method Details

.current_panel_fileObject



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

.excluded(klass = nil) ⇒ Object



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

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

.file_indexObject



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

.from_file(rel_path) ⇒ Object



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

.inherited(sub) ⇒ Object



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

.panel_exclusionObject



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

def panel_exclusion
  return @panel_exclusion ||= []
end

.panel_mappingsObject



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

def self.panel_mappings
  {}
end

Instance Method Details

#after(env, status, headers, body) ⇒ Object



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

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

#before(env) ⇒ Object



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

def before(env)
end

#call(env) ⇒ Object



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

#content_for_request(number) ⇒ Object



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

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

#has_content?Boolean

Returns:

  • (Boolean)


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

def has_content?
  true
end

#heading_for_request(number) ⇒ Object



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

#nameObject



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

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

#panel_appObject



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

def panel_app
  nil
end

#render(template) ⇒ Object



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

def render(template)
end