sql_tagger 0.0.2 → 0.0.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,8 +1,8 @@
1
1
  require 'sql_tagger'
2
2
  require 'mysql'
3
3
 
4
- class Mysql
5
- include SqlTagger::Initializer
4
+ module SqlTagger::Mysql
5
+ extend SqlTagger::ModuleMethods
6
6
 
7
7
  # @see Mysql#query
8
8
  def query_with_sql_tagger(sql, &block)
@@ -13,9 +13,6 @@ class Mysql
13
13
  def prepare_with_sql_tagger(query)
14
14
  prepare_without_sql_tagger(@sql_tagger.tag(query))
15
15
  end
16
-
17
- ['query', 'prepare'].each do |method|
18
- alias_method "#{method}_without_sql_tagger", method
19
- alias_method method, "#{method}_with_sql_tagger"
20
- end
21
16
  end
17
+
18
+ Mysql.send(:include, SqlTagger::Mysql)
@@ -0,0 +1,13 @@
1
+ require 'sql_tagger'
2
+ require 'mysql2'
3
+
4
+ module SqlTagger::Mysql2
5
+ extend SqlTagger::ModuleMethods
6
+
7
+ # @see Mysql2::Client#query
8
+ def query_with_sql_tagger(sql, opts ={})
9
+ query_without_sql_tagger(@sql_tagger.tag(sql), opts)
10
+ end
11
+ end
12
+
13
+ Mysql2::Client.send(:include, SqlTagger::Mysql2)
data/lib/sql_tagger.rb CHANGED
@@ -16,7 +16,7 @@ class SqlTagger
16
16
  attr_reader :exclusion_cache
17
17
 
18
18
  def initialize
19
- @exclusion_pattern = /^#{RbConfig::CONFIG['prefix']}|\/vendor\//
19
+ @exclusion_pattern = /^#{RbConfig::CONFIG['prefix']}|\/bundle\/|\/vendor\//
20
20
  @exclusion_cache = Set.new
21
21
  end
22
22
 
@@ -79,4 +79,18 @@ class SqlTagger
79
79
  initialize_without_sql_tagger(*args, &block)
80
80
  end
81
81
  end
82
+
83
+ module ModuleMethods
84
+ # Callback that includes SqlTagger::Initializer and does method aliasing.
85
+ #
86
+ # @param [Module] base
87
+ def included(base)
88
+ base.send(:include, SqlTagger::Initializer)
89
+ self.instance_methods.map(&:to_s).grep(/_with_sql_tagger$/).each do |with_method|
90
+ target = with_method.sub(/_with_sql_tagger$/, '')
91
+ base.send(:alias_method, "#{target}_without_sql_tagger", target)
92
+ base.send(:alias_method, target, with_method)
93
+ end
94
+ end
95
+ end
82
96
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'sql_tagger/mysql2'
3
+
4
+ describe Mysql2::Client do
5
+ before :all do
6
+ @db = Mysql2::Client.new
7
+ end
8
+
9
+ after :all do
10
+ @db.close
11
+ end
12
+
13
+ it_should_behave_like 'connections with sql_tagger'
14
+
15
+ describe '#query' do
16
+ it 'works' do
17
+ results = @db.query('SELECT 1 AS one', :symbolize_keys => true)
18
+ results.to_a.should == [{:one => 1}]
19
+ end
20
+
21
+ it 'calls SqlTagger#tag' do
22
+ @db.sql_tagger.should_receive(:tag).and_return('/* something.rb */ SELECT 1')
23
+ @db.query('SELECT 1')
24
+ end
25
+ end
26
+ end
data/sql_tagger.gemspec CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.add_development_dependency('rspec')
10
10
  s.add_development_dependency('mysql')
11
+ s.add_development_dependency('mysql2')
11
12
 
12
13
  s.files = ['MIT-LICENSE', 'README.rdoc', 'VERSION', 'sql_tagger.gemspec'] +
13
14
  Dir.glob('lib/**/*')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_tagger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Toby Hsieh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-16 00:00:00 -07:00
18
+ date: 2013-07-11 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,6 +46,20 @@ dependencies:
46
46
  version: "0"
47
47
  type: :development
48
48
  version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: mysql2
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
49
63
  description: sql_tagger inserts stack trace comments into SQL queries.
50
64
  email:
51
65
  executables: []
@@ -60,8 +74,10 @@ files:
60
74
  - VERSION
61
75
  - sql_tagger.gemspec
62
76
  - lib/sql_tagger/mysql.rb
77
+ - lib/sql_tagger/mysql2.rb
63
78
  - lib/sql_tagger.rb
64
79
  - spec/spec_helper.rb
80
+ - spec/sql_tagger/mysql2_spec.rb
65
81
  - spec/sql_tagger/mysql_spec.rb
66
82
  - spec/sql_tagger_spec.rb
67
83
  has_rdoc: true
@@ -100,5 +116,6 @@ specification_version: 3
100
116
  summary: Stack trace comments for SQL queries
101
117
  test_files:
102
118
  - spec/spec_helper.rb
119
+ - spec/sql_tagger/mysql2_spec.rb
103
120
  - spec/sql_tagger/mysql_spec.rb
104
121
  - spec/sql_tagger_spec.rb