Class: Rack::Bug::SQLPanel
- Inherits:
-
Panel
- Object
- Panel
- Rack::Bug::SQLPanel
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
Class Method Details
.queries ⇒ Object
35
36
37
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 35
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
|
.record_event(sql, duration, backtrace = []) ⇒ Object
26
27
28
29
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 26
def self.record_event(sql, duration, backtrace = [])
return unless Rack::Bug.enabled?
queries << Query.new(sql, duration, backtrace)
end
|
.reset ⇒ Object
31
32
33
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 31
def self.reset
Thread.current["rack.test.queries"] = []
end
|
.total_time ⇒ Object
39
40
41
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 39
def self.total_time
(queries.inject(0) { |memo, query| memo + query.time}) * 1_000
end
|
Instance Method Details
#content ⇒ Object
51
52
53
54
55
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 51
def content
result = render_template "panels/sql", :queries => self.class.queries
self.class.reset
return result
end
|
#heading ⇒ Object
47
48
49
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 47
def heading
"#{self.class.queries.size} Queries (%.2fms)" % self.class.total_time
end
|
#name ⇒ Object
43
44
45
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 43
def name
"sql"
end
|
#panel_app ⇒ Object
12
13
14
|
# File 'lib/rack/bug/panels/sql_panel.rb', line 12
def panel_app
PanelApp.new
end
|