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



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

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

.recordsObject



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

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

.resetObject



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

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

.totalObject



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

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

Instance Method Details

#contentObject



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

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



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

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

#nameObject



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

def name
  "active_record"
end