peek-active_record 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ``` ruby
22
22
  # config/initializers/peek.rb
23
- Peek.into Peek::Views::ActiveRecord
23
+ Peek.into Peek::Views::ActiveRecord, :type_tracking => false
24
24
  ```
25
25
 
26
26
  ``` coffee
@@ -1,6 +1,12 @@
1
1
  $(document).on 'peek:update', ->
2
2
  arContext = $('#peek-context-active-record')
3
3
  if arContext.size()
4
- context = arContext.data('context')
5
- objects = context.object_count
6
- $('#active_record-tooltip').attr('title', "#{objects} AR Objects").tipsy()
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})
@@ -1,3 +1,2 @@
1
- require "peek/extensions/active_record"
2
1
  require "peek/views/active_record"
3
2
  require "peek-active_record/railtie"
@@ -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
- if ActiveRecord::Base.obj_types.has_key? self.class.name
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 "atomic"
1
+ require "peek/extensions/active_record"
2
2
 
3
3
  module Peek
4
4
  module Views
5
5
  class ActiveRecord < View
6
- def result
7
- { :objects => ::ActiveRecord::Base.obj_count.value }
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
- Hash.new.tap do |ctx|
12
- ctx[:object_count] = ::ActiveRecord::Base.obj_count.value
13
- ctx[:object_types] = ::ActiveRecord::Base.obj_types
14
- end
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 { |ar| ar.obj_count = Atomic.new(0) }
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
@@ -2,7 +2,7 @@
2
2
  #
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "peek-active_record"
5
- spec.version = "0.3.0"
5
+ spec.version = "0.4.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.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: