peek-active_record 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
|
|
1
1
|
require "active_record"
|
2
|
+
require "atomic"
|
2
3
|
|
3
4
|
class ActiveRecord::Base
|
4
5
|
class << self
|
5
6
|
attr_accessor :obj_count, :obj_types, :obj_types_enabled
|
6
7
|
end
|
7
8
|
|
8
|
-
self.obj_count = 0
|
9
|
+
self.obj_count = Atomic.new(0)
|
9
10
|
self.obj_types = Hash.new(0)
|
10
11
|
self.obj_types_enabled = false
|
11
12
|
|
@@ -33,10 +34,14 @@ class ActiveRecord::Base
|
|
33
34
|
|
34
35
|
protected
|
35
36
|
def _update_object_stats
|
36
|
-
ActiveRecord::Base.obj_count
|
37
|
+
ActiveRecord::Base.obj_count.update { |val| val + 1 }
|
37
38
|
|
38
39
|
if ActiveRecord::Base.obj_types_enabled
|
39
|
-
ActiveRecord::Base.obj_types
|
40
|
+
if ActiveRecord::Base.obj_types.has_key? self.class.name
|
41
|
+
ActiveRecord::Base.obj_types[self.class.name].update { |val| val + 1 }
|
42
|
+
else
|
43
|
+
ActiveRecord::Base.obj_types[self.class.name] = Atomic.new(1)
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
require "atomic"
|
2
|
+
|
1
3
|
module Peek
|
2
4
|
module Views
|
3
5
|
class ActiveRecord < View
|
4
6
|
def result
|
5
|
-
{ :objects => ::ActiveRecord::Base.obj_count }
|
7
|
+
{ :objects => ::ActiveRecord::Base.obj_count.value }
|
6
8
|
end
|
7
9
|
|
8
10
|
def context
|
9
11
|
Hash.new.tap do |ctx|
|
10
|
-
ctx[:object_count] = ::ActiveRecord::Base.obj_count
|
12
|
+
ctx[:object_count] = ::ActiveRecord::Base.obj_count.value
|
11
13
|
ctx[:object_types] = ::ActiveRecord::Base.obj_types
|
12
14
|
end
|
13
15
|
end
|
@@ -16,7 +18,7 @@ module Peek
|
|
16
18
|
|
17
19
|
def setup_subscribers
|
18
20
|
before_request do
|
19
|
-
::ActiveRecord::Base.tap { |ar| ar.obj_count = 0 }
|
21
|
+
::ActiveRecord::Base.tap { |ar| ar.obj_count = Atomic.new(0) }
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/peek-active_record.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "peek-active_record"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.2.0"
|
6
6
|
spec.authors = ["Will Farrington"]
|
7
7
|
spec.email = ["wfarr@github.com"]
|
8
8
|
spec.description = %q{Peek into your ActiveRecord stats.}
|
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
18
|
spec.add_dependency "activerecord", "~> 3.2.0"
|
19
|
+
spec.add_dependency "atomic", ">= 1.0.0"
|
20
|
+
spec.add_dependency "peek"
|
19
21
|
|
20
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
23
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peek-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,38 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: atomic
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: peek
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
30
62
|
- !ruby/object:Gem::Dependency
|
31
63
|
name: bundler
|
32
64
|
requirement: !ruby/object:Gem::Requirement
|