peek-active_record 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peek-active_record.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Will Farrington
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Peek::ActiveRecord
2
+
3
+ Peek into your ActiveRecord stats.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'peek-active_record'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install peek-active_record
18
+
19
+ ## Usage
20
+
21
+ ``` ruby
22
+ # config/initializers/peek.rb
23
+ Peek.into Peek::Views::ActiveRecord
24
+ ```
25
+
26
+ ``` coffee
27
+ # app/assets/application.coffee
28
+ #= require 'peek/views/active_record'
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ $(document).on 'peek:update', ->
2
+ arContext = $('#peek-context-active-record')
3
+ if arContext.size()
4
+ context = arContext.data('context')
5
+ objects = context.object_count
6
+ $('#active_record-tooltip').attr('title', "#{objects} AR Objects").tipsy()
@@ -0,0 +1,3 @@
1
+ require "peek/extensions/active_record"
2
+ require "peek/views/active_record"
3
+ require "peek-active_record/railtie"
@@ -0,0 +1,6 @@
1
+ module Peek
2
+ module ActiveRecord
3
+ class Railtie < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ require "active_record"
2
+
3
+ class ActiveRecord::Base
4
+ class << self
5
+ attr_accessor :obj_count, :obj_types, :obj_types_enabled
6
+ end
7
+
8
+ self.obj_count = 0
9
+ self.obj_types = Hash.new(0)
10
+ self.obj_types_enabled = false
11
+
12
+ def initialize_with_stats *attributes
13
+ initialize_without_stats *attributes
14
+ ensure
15
+ _update_object_stats
16
+ end
17
+
18
+ def init_with_with_stats coder
19
+ init_with_without_stats coder
20
+ ensure
21
+ _update_object_stats
22
+ end
23
+
24
+ def initialize_dup_with_stats other
25
+ intialize_dup_without_stats other
26
+ ensure
27
+ _update_object_stats
28
+ end
29
+
30
+ alias_method_chain :initialize, :stats
31
+ alias_method_chain :init_with, :stats
32
+ alias_method_chain :initialize_dup, :stats
33
+
34
+ protected
35
+ def _update_object_stats
36
+ ActiveRecord::Base.obj_count += 1
37
+
38
+ if ActiveRecord::Base.obj_types_enabled
39
+ ActiveRecord::Base.obj_types[ self.class.name ] += 1
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ module Peek
2
+ module Views
3
+ class ActiveRecord < View
4
+ def result
5
+ { :objects => ::ActiveRecord::Base.obj_count }
6
+ end
7
+
8
+ def context
9
+ Hash.new.tap do |ctx|
10
+ ctx[:object_count] = ::ActiveRecord::Base.obj_count
11
+ ctx[:object_types] = ::ActiveRecord::Base.obj_types
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def setup_subscribers
18
+ before_request do
19
+ ::ActiveRecord::Base.tap { |ar| ar.obj_count = 0 }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ #
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "peek-active_record"
5
+ spec.version = "0.0.1"
6
+ spec.authors = ["Will Farrington"]
7
+ spec.email = ["wfarr@github.com"]
8
+ spec.description = %q{Peek into your ActiveRecord stats.}
9
+ spec.summary = %q{Peek into your ActiveRecord stats.}
10
+ spec.homepage = "https://github.com/wfarr/peek-active_record"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "activerecord", "~> 3.2.0"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ bundle install --path .bundle --binstubs .bundle/binstubs "$@"
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peek-active_record
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Farrington
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Peek into your ActiveRecord stats.
63
+ email:
64
+ - wfarr@github.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - app/assets/javascripts/peek/views/active_record.coffee
75
+ - app/views/peek/views/_active_record.html.erb
76
+ - lib/peek-active_record.rb
77
+ - lib/peek-active_record/railtie.rb
78
+ - lib/peek/extensions/active_record.rb
79
+ - lib/peek/views/active_record.rb
80
+ - peek-active_record.gemspec
81
+ - script/bootstrap
82
+ homepage: https://github.com/wfarr/peek-active_record
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.23
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Peek into your ActiveRecord stats.
107
+ test_files: []