marginalia 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of marginalia might be problematic. Click here for more details.

data/README.md CHANGED
@@ -23,6 +23,11 @@ tested on Rails 2.3.5 through 3.2-stable. It has also been tested for sqlite3 an
23
23
 
24
24
  Patches are welcome for other database adapters.
25
25
 
26
+ **The preferred way to get support is to send an email to
27
+ marginalia@librelist.com. Github issues
28
+ and pull requests will be checked occassionally, but email is the
29
+ fastest way to get help.**
30
+
26
31
  ## Installation
27
32
 
28
33
  ### For Rails 3.x:
@@ -89,7 +94,7 @@ The calling controller is available to these methods via `@controller`.
89
94
  Marginalia ships with `:application`, `:controller`, and `:action` enabled by
90
95
  default. In addition, implementation is provided for:
91
96
  * `:line` (for file and line number calling query). :line supports
92
- a configuration by setting a regexp in `Marignalia::Comment.lines_to_ignore`
97
+ a configuration by setting a regexp in `Marginalia::Comment.lines_to_ignore`
93
98
  to exclude parts of the stacktrace from inclusion in the line comment.
94
99
 
95
100
  Pull requests for other included comment components are welcome.
@@ -1,18 +1,27 @@
1
+ require 'socket'
2
+
1
3
  module Marginalia
2
4
  module Comment
3
- mattr_accessor :components, :comment, :lines_to_ignore
5
+ mattr_accessor :components, :lines_to_ignore
4
6
 
5
7
  def self.update!(controller = nil)
6
8
  @controller = controller
7
- self.comment = self.components.collect{|c| "#{c}:#{self.send(c) }" }.join(",")
8
9
  end
9
10
 
10
- def self.to_s
11
- self.comment
11
+ def self.construct_comment
12
+ ret = ''
13
+ self.components.each do |c|
14
+ component_value = self.send(c)
15
+ if component_value.present?
16
+ ret << ',' if ret.present?
17
+ ret << c.to_s << ':' << component_value.to_s
18
+ end
19
+ end
20
+ ret
12
21
  end
13
22
 
14
23
  def self.clear!
15
- self.comment = nil
24
+ @controller = nil
16
25
  end
17
26
 
18
27
  private
@@ -36,7 +45,9 @@ module Marginalia
36
45
 
37
46
  def self.line
38
47
  Marginalia::Comment.lines_to_ignore ||= /\.rvm|gem|vendor|marginalia|rbenv/
39
- last_line = caller.detect { |line| line !~ Marginalia::Comment.lines_to_ignore }
48
+ last_line = caller.detect do |line|
49
+ line !~ Marginalia::Comment.lines_to_ignore
50
+ end
40
51
  if last_line
41
52
  root = if defined?(Rails) && Rails.respond_to?(:root)
42
53
  Rails.root.to_s
@@ -52,6 +63,14 @@ module Marginalia
52
63
  end
53
64
  end
54
65
 
66
+ def self.hostname
67
+ @cached_hostname ||= Socket.gethostname
68
+ end
69
+
70
+ def self.pid
71
+ Process.pid
72
+ end
73
+
55
74
  end
56
75
 
57
76
  end
@@ -52,6 +52,7 @@ module Marginalia
52
52
  end
53
53
  end
54
54
 
55
+ # SQL queries made through PostgreSQLAdapter#exec_delete will not be annotated.
55
56
  if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
56
57
  if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
57
58
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.module_eval do
data/lib/marginalia.rb CHANGED
@@ -11,12 +11,28 @@ module Marginalia
11
11
  if defined? :execute
12
12
  alias_method :execute_without_marginalia, :execute
13
13
  alias_method :execute, :execute_with_marginalia
14
+ elsif defined? :exec_query
15
+ alias_method :exec_query_without_marginalia, :exec_query
16
+ alias_method :exec_query, :exec_query_with_marginalia
14
17
  end
15
18
  end
16
19
  end
17
20
 
21
+ def annotate_sql(sql)
22
+ comment = Marginalia::Comment.construct_comment
23
+ if comment.present?
24
+ "#{sql} /*#{comment}*/"
25
+ else
26
+ sql
27
+ end
28
+ end
29
+
18
30
  def execute_with_marginalia(sql, name = nil)
19
- execute_without_marginalia("#{sql} /*#{Marginalia::Comment.to_s}*/", name)
31
+ execute_without_marginalia(annotate_sql(sql), name)
32
+ end
33
+
34
+ def exec_query_with_marginalia(sql, name = 'SQL', binds = [])
35
+ exec_query_without_marginalia(annotate_sql(sql), name, binds)
20
36
  end
21
37
  end
22
38
 
data/marginalia.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.test_files = `git ls-files -- {test}/*`.split("\n")
9
9
  gem.name = "marginalia"
10
10
  gem.require_paths = ["lib"]
11
- gem.version = "1.1.0"
11
+ gem.version = "1.1.1"
12
12
 
13
13
  gem.add_runtime_dependency "actionpack", ">= 2.3", "< 3.3"
14
14
  gem.add_runtime_dependency "activerecord", ">= 2.3", "< 3.3"
@@ -43,7 +43,7 @@ class MarginaliaTest < Test::Unit::TestCase
43
43
 
44
44
  def test_query_commenting_on_mysql_driver_with_no_action
45
45
  ActiveRecord::Base.connection.execute "select id from posts"
46
- assert_match %r{select id from posts /\*\*/$}, @queries.first
46
+ assert_match %r{select id from posts /\*application:rails\*/$}, @queries.first
47
47
  end
48
48
 
49
49
  def test_query_commenting_on_mysql_driver_with_action
@@ -68,14 +68,27 @@ class MarginaliaTest < Test::Unit::TestCase
68
68
  def test_last_line_component
69
69
  Marginalia::Comment.components = [:line]
70
70
  PostsController.action(:driver_only).call(@env)
71
- assert_match %r{/\*line:test/query_comments_test.rb:[0-9]*:in `call'\*/$}, @queries.first
71
+
72
+ # Because "lines_to_ignore" by default includes "marginalia" and "gem", the
73
+ # extracted line line will be from the line in this file that actually
74
+ # triggers the query.
75
+ assert_match %r{/\*line:test/query_comments_test.rb:[0-9]+:in `driver_only'\*/$}, @queries.first
72
76
  end
73
77
 
74
78
  def test_last_line_component_with_lines_to_ignore
75
79
  Marginalia::Comment.lines_to_ignore = /foo bar/
76
80
  Marginalia::Comment.components = [:line]
77
81
  PostsController.action(:driver_only).call(@env)
78
- assert_match %r{/\*line:.*lib/marginalia/comment.rb:7:in .*?\*/$}, @queries.first
82
+ # Because "lines_to_ignore" does not include "marginalia", the extracted
83
+ # line will be from marginalia/comment.rb.
84
+ assert_match %r{/\*line:.*lib/marginalia/comment.rb:[0-9]+}, @queries.first
85
+ end
86
+
87
+ def test_hostname_and_pid
88
+ Marginalia::Comment.components = [:hostname, :pid]
89
+ PostsController.action(:driver_only).call(@env)
90
+ assert_match %r{/\*hostname:#{Socket.gethostname},pid:#{Process.pid}\*/$}, @queries.first
91
+
79
92
  end
80
93
 
81
94
  def teardown
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marginalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-30 00:00:00.000000000 Z
14
+ date: 2013-03-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: actionpack
18
- requirement: &9071720 !ruby/object:Gem::Requirement
18
+ requirement: &14428020 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -26,10 +26,10 @@ dependencies:
26
26
  version: '3.3'
27
27
  type: :runtime
28
28
  prerelease: false
29
- version_requirements: *9071720
29
+ version_requirements: *14428020
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activerecord
32
- requirement: &9070320 !ruby/object:Gem::Requirement
32
+ requirement: &14425760 !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
@@ -40,10 +40,10 @@ dependencies:
40
40
  version: '3.3'
41
41
  type: :runtime
42
42
  prerelease: false
43
- version_requirements: *9070320
43
+ version_requirements: *14425760
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: rake
46
- requirement: &9069220 !ruby/object:Gem::Requirement
46
+ requirement: &14424740 !ruby/object:Gem::Requirement
47
47
  none: false
48
48
  requirements:
49
49
  - - ! '>='
@@ -51,10 +51,10 @@ dependencies:
51
51
  version: '0'
52
52
  type: :development
53
53
  prerelease: false
54
- version_requirements: *9069220
54
+ version_requirements: *14424740
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mysql
57
- requirement: &9058300 !ruby/object:Gem::Requirement
57
+ requirement: &14423440 !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
60
  - - ! '>='
@@ -62,10 +62,10 @@ dependencies:
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
- version_requirements: *9058300
65
+ version_requirements: *14423440
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: mysql2
68
- requirement: &9057600 !ruby/object:Gem::Requirement
68
+ requirement: &14422580 !ruby/object:Gem::Requirement
69
69
  none: false
70
70
  requirements:
71
71
  - - ! '>='
@@ -73,10 +73,10 @@ dependencies:
73
73
  version: '0'
74
74
  type: :development
75
75
  prerelease: false
76
- version_requirements: *9057600
76
+ version_requirements: *14422580
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: pg
79
- requirement: &9057080 !ruby/object:Gem::Requirement
79
+ requirement: &17277820 !ruby/object:Gem::Requirement
80
80
  none: false
81
81
  requirements:
82
82
  - - ! '>='
@@ -84,10 +84,10 @@ dependencies:
84
84
  version: '0'
85
85
  type: :development
86
86
  prerelease: false
87
- version_requirements: *9057080
87
+ version_requirements: *17277820
88
88
  - !ruby/object:Gem::Dependency
89
89
  name: sqlite3
90
- requirement: &9055100 !ruby/object:Gem::Requirement
90
+ requirement: &17276680 !ruby/object:Gem::Requirement
91
91
  none: false
92
92
  requirements:
93
93
  - - ! '>='
@@ -95,7 +95,7 @@ dependencies:
95
95
  version: '0'
96
96
  type: :development
97
97
  prerelease: false
98
- version_requirements: *9055100
98
+ version_requirements: *17276680
99
99
  description:
100
100
  email:
101
101
  - noah@37signals.com