active_record-comments 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_record/comments.rb +51 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3479f24b30ad73efbf9937f33c94c3f722e8dac7
4
- data.tar.gz: 4f399eabfb49d657ffb82dcd702eb66ee20a54bb
3
+ metadata.gz: a9cad33bbee4634a2c13b3d6c108da34ac7c50e2
4
+ data.tar.gz: ec4874db0062e24adccd9865022120a17f9f9c52
5
5
  SHA512:
6
- metadata.gz: 19a92d96e8c9faebeb5b9a0d34287e9abd150f3fd98f9296fd01e286178f8c4f95687cca52db24976a33b8dde38dd291c10c980f8fae7b71d7eec46c574a492e
7
- data.tar.gz: bd39c3c075ec5a66b1a2db8566abd48675fd3a64af43c6bd12d1e1b62a088c70f04da3f64fdac96f5104b40c83f951cab192f1e14c25bd7cf4e599027bc0f96b
6
+ metadata.gz: e68299120b751403d0dd037db7871ff60db3a523693bb248313a91f44255aeb438b651fb290b7113f5127597e9b4737215990c6c84f9dd0cb6b9a661db2ea84c
7
+ data.tar.gz: ab64379e0934eee080442aec23049c8af2b9f30c33f9ed3f50da02888ce3f00978b584f6c007b96316b158671d7b50fdcbcb631d700a69a9cd5013b0d99c1842
@@ -2,6 +2,56 @@ require "active_record"
2
2
 
3
3
  module ActiveRecord
4
4
  module Comments
5
+ module ExecuteWithComments
6
+ class << self
7
+ def included(base)
8
+ base.class_eval do
9
+ # 99% case
10
+ if base.method_defined?(:execute)
11
+ alias_method :execute_without_comment, :execute
12
+ def execute(query, *args, &block)
13
+ query = ActiveRecord::Comments.with_comment_sql(query)
14
+ execute_without_comment(query, *args, &block)
15
+ end
16
+ end
17
+
18
+ # ActiveRecord 3.2 vs sqlite, maybe others ...
19
+ if base.method_defined?(:exec_query)
20
+ alias_method :exec_query_without_comment, :exec_query
21
+ def exec_query(query, *args, &block)
22
+ query = ActiveRecord::Comments.with_comment_sql(query)
23
+ exec_query_without_comment(query, *args, &block)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def install!
30
+ if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
31
+ install ActiveRecord::ConnectionAdapters::SQLite3Adapter
32
+ end
33
+
34
+ if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
35
+ install ActiveRecord::ConnectionAdapters::MysqlAdapter
36
+ end
37
+
38
+ if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
39
+ install ActiveRecord::ConnectionAdapters::Mysql2Adapter
40
+ end
41
+
42
+ if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
43
+ install ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def install(adapter)
50
+ adapter.send(:include, ::ActiveRecord::Comments::ExecuteWithComments)
51
+ end
52
+ end
53
+ end
54
+
5
55
  class << self
6
56
  def comment(comment)
7
57
  @comment ||= []
@@ -25,11 +75,4 @@ module ActiveRecord
25
75
  end
26
76
  end
27
77
 
28
- # log is called by execute in all db adapters
29
- ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
30
- def log_with_comment_injection(query, *args, &block)
31
- query = ActiveRecord::Comments.with_comment_sql(query)
32
- log_without_comment_injection(query, *args, &block)
33
- end
34
- alias_method_chain :log, :comment_injection
35
- end
78
+ ActiveRecord::Comments::ExecuteWithComments.install!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-02 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord