peek-active_record 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
$(document).on 'peek:update', ->
|
2
2
|
arContext = $('#peek-context-active-record')
|
3
3
|
if arContext.size()
|
4
|
-
context
|
5
|
-
objects
|
6
|
-
|
4
|
+
context = arContext.data('context')
|
5
|
+
objects = context.object_count
|
6
|
+
object_types = context.object_types
|
7
|
+
|
8
|
+
title = "<strong>#{objects} AR Objects</strong>"
|
9
|
+
for key, val of object_types
|
10
|
+
title += "<br>#{val} #{key}"
|
11
|
+
|
12
|
+
$('#active_record-tooltip').attr('title', title).tipsy({html: true})
|
data/lib/peek-active_record.rb
CHANGED
@@ -17,11 +17,7 @@ class ActiveRecord::Base
|
|
17
17
|
ActiveRecord::Base.obj_count.update { |val| val + 1 }
|
18
18
|
|
19
19
|
if ActiveRecord::Base.obj_types_enabled
|
20
|
-
|
21
|
-
ActiveRecord::Base.obj_types[self.class.name].update { |val| val + 1 }
|
22
|
-
else
|
23
|
-
ActiveRecord::Base.obj_types[self.class.name] = Atomic.new(1)
|
24
|
-
end
|
20
|
+
ActiveRecord::Base.obj_types[self.class.name] += 1
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
@@ -1,24 +1,38 @@
|
|
1
|
-
require "
|
1
|
+
require "peek/extensions/active_record"
|
2
2
|
|
3
3
|
module Peek
|
4
4
|
module Views
|
5
5
|
class ActiveRecord < View
|
6
|
-
def
|
7
|
-
|
6
|
+
def initialize options = {}
|
7
|
+
@type_tracking = options.fetch(:type_tracking, false)
|
8
|
+
|
9
|
+
setup_subscribers
|
8
10
|
end
|
9
11
|
|
10
12
|
def context
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
{
|
14
|
+
:object_count => object_count,
|
15
|
+
:object_types => object_types
|
16
|
+
}
|
15
17
|
end
|
16
18
|
|
19
|
+
|
17
20
|
private
|
21
|
+
def object_count
|
22
|
+
::ActiveRecord::Base.obj_count.value
|
23
|
+
end
|
24
|
+
|
25
|
+
def object_types
|
26
|
+
Hash[::ActiveRecord::Base.obj_types.sort_by(&:last).reverse]
|
27
|
+
end
|
18
28
|
|
19
29
|
def setup_subscribers
|
20
30
|
before_request do
|
21
|
-
::ActiveRecord::Base.tap
|
31
|
+
::ActiveRecord::Base.tap do |ar|
|
32
|
+
ar.obj_count = Atomic.new(0)
|
33
|
+
ar.obj_types = Hash.new(0)
|
34
|
+
ar.obj_types_enabled = @type_tracking
|
35
|
+
end
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
data/peek-active_record.gemspec
CHANGED