Class: Rack::Bug::SQLPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/bug/panels/sql_panel.rb,
lib/rack/bug/panels/sql_panel/query.rb,
lib/rack/bug/panels/sql_panel/panel_app.rb

Defined Under Namespace

Classes: PanelApp, Query

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Panel

#after, #before, #call, #has_content?, #initialize, #render

Methods included from Render

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

Constructor Details

This class inherits a constructor from Rack::Bug::Panel

Class Method Details

.queriesObject



30
31
32
# File 'lib/rack/bug/panels/sql_panel.rb', line 30

def self.queries
  Thread.current["rack.test.queries"] ||= []
end

.record(sql, backtrace = [], &block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rack/bug/panels/sql_panel.rb', line 16

def self.record(sql, backtrace = [], &block)
  return block.call unless Rack::Bug.enabled?

  start_time = Time.now
  result = block.call
  queries << Query.new(sql, Time.now - start_time, backtrace)

  return result
end

.resetObject



26
27
28
# File 'lib/rack/bug/panels/sql_panel.rb', line 26

def self.reset
  Thread.current["rack.test.queries"] = []
end

.total_timeObject



34
35
36
# File 'lib/rack/bug/panels/sql_panel.rb', line 34

def self.total_time
  (queries.inject(0) { |memo, query| memo + query.time}) * 1_000
end

Instance Method Details

#contentObject



46
47
48
49
50
# File 'lib/rack/bug/panels/sql_panel.rb', line 46

def content
  result = render_template "panels/sql", :queries => self.class.queries
  self.class.reset
  return result
end

#headingObject



42
43
44
# File 'lib/rack/bug/panels/sql_panel.rb', line 42

def heading
  "#{self.class.queries.size} Queries (%.2fms)" % self.class.total_time
end

#nameObject



38
39
40
# File 'lib/rack/bug/panels/sql_panel.rb', line 38

def name
  "sql"
end

#panel_appObject



12
13
14
# File 'lib/rack/bug/panels/sql_panel.rb', line 12

def panel_app
  PanelApp.new
end