peek-active_record 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,6 +28,10 @@ Peek.into Peek::Views::ActiveRecord
28
28
  #= require 'peek/views/active_record'
29
29
  ```
30
30
 
31
+ Then, in any ActiveRecord model you wish to watch allocations of
32
+ (please note that after_initialize does impair performance of your app slightly)
33
+ simply include the `Peek::ActiveRecord::ObjectStats` module.
34
+
31
35
  ## Contributing
32
36
 
33
37
  1. Fork it
@@ -0,0 +1,13 @@
1
+ require "active_support/concern"
2
+
3
+ module Peek
4
+ module ActiveRecord
5
+ module ObjectStats
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ after_initialize :_update_object_stats
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,8 @@
1
1
  require "active_record"
2
2
  require "atomic"
3
3
 
4
+ require "peek/active_record/object_stats"
5
+
4
6
  class ActiveRecord::Base
5
7
  class << self
6
8
  attr_accessor :obj_count, :obj_types, :obj_types_enabled
@@ -10,28 +12,6 @@ class ActiveRecord::Base
10
12
  self.obj_types = Hash.new(0)
11
13
  self.obj_types_enabled = false
12
14
 
13
- def initialize_with_stats *attributes
14
- initialize_without_stats *attributes
15
- ensure
16
- _update_object_stats
17
- end
18
-
19
- def init_with_with_stats coder
20
- init_with_without_stats coder
21
- ensure
22
- _update_object_stats
23
- end
24
-
25
- def initialize_dup_with_stats other
26
- intialize_dup_without_stats other
27
- ensure
28
- _update_object_stats
29
- end
30
-
31
- alias_method_chain :initialize, :stats
32
- alias_method_chain :init_with, :stats
33
- alias_method_chain :initialize_dup, :stats
34
-
35
15
  protected
36
16
  def _update_object_stats
37
17
  ActiveRecord::Base.obj_count.update { |val| val + 1 }
@@ -2,7 +2,7 @@
2
2
  #
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "peek-active_record"
5
- spec.version = "0.2.0"
5
+ spec.version = "0.3.0"
6
6
  spec.authors = ["Will Farrington"]
7
7
  spec.email = ["wfarr@github.com"]
8
8
  spec.description = %q{Peek into your ActiveRecord stats.}
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.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -107,6 +107,7 @@ files:
107
107
  - app/views/peek/views/_active_record.html.erb
108
108
  - lib/peek-active_record.rb
109
109
  - lib/peek-active_record/railtie.rb
110
+ - lib/peek/active_record/object_stats.rb
110
111
  - lib/peek/extensions/active_record.rb
111
112
  - lib/peek/views/active_record.rb
112
113
  - peek-active_record.gemspec