Class: Rack::Bug::ActiveRecordPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/bug/panels/active_record_panel.rb

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, #panel_app, #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

.record(class_name) ⇒ Object



9
10
11
12
# File 'lib/rack/bug/panels/active_record_panel.rb', line 9

def self.record(class_name)
  return unless Rack::Bug.enabled?
  records[class_name] += 1
end

.recordsObject



18
19
20
# File 'lib/rack/bug/panels/active_record_panel.rb', line 18

def self.records
  Thread.current["rack.bug.active_records"] ||= Hash.new { 0 }
end

.resetObject



14
15
16
# File 'lib/rack/bug/panels/active_record_panel.rb', line 14

def self.reset
  Thread.current["rack.bug.active_records"] = Hash.new { 0 }
end

.totalObject



22
23
24
25
26
# File 'lib/rack/bug/panels/active_record_panel.rb', line 22

def self.total
  records.inject(0) do |memo, (key, value)|
    memo + value
  end
end

Instance Method Details

#contentObject



36
37
38
39
40
41
# File 'lib/rack/bug/panels/active_record_panel.rb', line 36

def content
  records = self.class.records.to_a.sort_by { |key, value| value }.reverse
  result = render_template "panels/active_record", :records => records
  self.class.reset
  result
end

#headingObject



32
33
34
# File 'lib/rack/bug/panels/active_record_panel.rb', line 32

def heading
  "#{self.class.total} AR Objects"
end

#nameObject



28
29
30
# File 'lib/rack/bug/panels/active_record_panel.rb', line 28

def name
  "active_record"
end