active-record-query-trace 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,11 @@
1
+ Requirements
2
+ ============
3
+ Rails 3+
4
+
5
+ ActiveRecordQueryTrace
6
+ ======================
7
+ Enable plugin to log the source of SQL queries to Rails logger. I made this a plugin versus a Gem so its easier to enable/disable on demand. Otherwise it can cruft up the logs pretty easy.
8
+
9
+ To disable just comment out the require() in init.rb
10
+
11
+ Copyright (c) 2011 Cody Caughlan, released under the MIT license
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the active_record_query_trace plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the active_record_query_trace plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'ActiveRecordQueryTrace'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'active_support/log_subscriber'
2
+ require 'active-record-query-trace'
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,21 @@
1
+ module QueryTrace
2
+ module ActiveRecord
3
+ class LogSubscriber < ActiveSupport::LogSubscriber
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def sql(event)
10
+ #debug("#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}")
11
+ debug("\e[1m\e[35m\e[1m\e[47mCalled from:\e[0m " + clean_trace(caller[2..-2]).join("\n "))
12
+ end
13
+
14
+ def clean_trace(trace)
15
+ Rails.respond_to?(:backtrace_cleaner) ? Rails.backtrace_cleaner.clean(trace) : trace
16
+ end
17
+
18
+ attach_to :active_record
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveRecordQueryTraceTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active-record-query-trace
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Cody Caughlan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-07 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Query Backtrace for ActiveRecord
17
+ email:
18
+ - toolbag@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - MIT-LICENSE
27
+ - README
28
+ - Rakefile
29
+ - init.rb
30
+ - install.rb
31
+ - lib/active-record-query-trace.rb
32
+ - test/active_record_query_trace_test.rb
33
+ - test/test_helper.rb
34
+ - uninstall.rb
35
+ homepage: ""
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.9
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Query Backtrace for ActiveRecord
62
+ test_files:
63
+ - test/active_record_query_trace_test.rb
64
+ - test/test_helper.rb