active_record-comments 0.1.3 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cf15c21750c806f5bdb24a514c2f28d0bd03d166
4
- data.tar.gz: c24c12d8b6f8bc3775358967abcf054cc6e38f1c
2
+ SHA256:
3
+ metadata.gz: 4a76c496fde5150801ae8376a7ca62cae2601a02f3f3fcd95be8b3bcbd876727
4
+ data.tar.gz: 20875accc2da7dcb9568411681c35210fa83726b6da9aac6d22fd234283a3f49
5
5
  SHA512:
6
- metadata.gz: 1ff24880b18d55974018784f6597ea57aa34cc92b51011a85c371d6520d7d1c176f767a6e0e349a376ca07d281c8715b63c7b0409758c6b300533ea5e39d26d1
7
- data.tar.gz: a88d754b531c0ce90dbe2a9256ec063f24804aeeaf5c8d30a3b5675eab4416bc79d3a4b8606e2c27703b73956b00ba9cb0c8bdccb962d030d42773928c5c7cb5
6
+ metadata.gz: 855b507aeecdced9e9c52b089fd40b973bc90c34a42b6c48f3a4484661d836b4bb7282cf31a7c32774e6e384359082cc7f3ecbc85ff28300d04666106958cf1e
7
+ data.tar.gz: aaf14ebac79e0452dc5ff3c4e95098ebb9415833f6e00deb53d4914cf803a4ff4d215a8094f5ce0a1419524811affc7207a71f589d00c32537ab784b2d82f16a
@@ -0,0 +1,52 @@
1
+ module ActiveRecord
2
+ module Comments
3
+ module ExecuteWithComments
4
+ class << self
5
+ def included(base)
6
+ base.class_eval do
7
+ # ActiveRecord 3.2 vs sqlite, maybe others ...
8
+ if base.method_defined?(:exec_query)
9
+ alias_method :exec_query_without_comment, :exec_query
10
+ def exec_query(query, *args, &block)
11
+ query = ActiveRecord::Comments.with_comment_sql(query)
12
+ exec_query_without_comment(query, *args, &block)
13
+ end
14
+
15
+ # 99% case
16
+ elsif base.method_defined?(:execute)
17
+ alias_method :execute_without_comment, :execute
18
+ def execute(query, *args, &block)
19
+ query = ActiveRecord::Comments.with_comment_sql(query)
20
+ execute_without_comment(query, *args, &block)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def install!
27
+ if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
28
+ install ActiveRecord::ConnectionAdapters::SQLite3Adapter
29
+ end
30
+
31
+ if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
32
+ install ActiveRecord::ConnectionAdapters::MysqlAdapter
33
+ end
34
+
35
+ if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
36
+ install ActiveRecord::ConnectionAdapters::Mysql2Adapter
37
+ end
38
+
39
+ if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
40
+ install ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def install(adapter)
47
+ adapter.send(:include, ::ActiveRecord::Comments::ExecuteWithComments)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module Comments
3
+ VERSION = "0.4.0"
4
+ end
5
+ end
@@ -1,57 +1,16 @@
1
+ require "active_record/comments/execute_with_comments"
2
+ require "active_record/comments/version"
1
3
  require "active_record"
2
4
 
3
5
  module ActiveRecord
4
6
  module Comments
5
- module ExecuteWithComments
6
- class << self
7
- def included(base)
8
- base.class_eval do
9
- # ActiveRecord 3.2 vs sqlite, maybe others ...
10
- if base.method_defined?(:exec_query)
11
- alias_method :exec_query_without_comment, :exec_query
12
- def exec_query(query, *args, &block)
13
- query = ActiveRecord::Comments.with_comment_sql(query)
14
- exec_query_without_comment(query, *args, &block)
15
- end
16
-
17
- # 99% case
18
- elsif base.method_defined?(:execute)
19
- alias_method :execute_without_comment, :execute
20
- def execute(query, *args, &block)
21
- query = ActiveRecord::Comments.with_comment_sql(query)
22
- execute_without_comment(query, *args, &block)
23
- end
24
- end
25
- end
26
- end
27
-
28
- def install!
29
- if defined? ActiveRecord::ConnectionAdapters::SQLite3Adapter
30
- install ActiveRecord::ConnectionAdapters::SQLite3Adapter
31
- end
32
-
33
- if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
34
- install ActiveRecord::ConnectionAdapters::MysqlAdapter
35
- end
36
-
37
- if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
38
- install ActiveRecord::ConnectionAdapters::Mysql2Adapter
39
- end
40
-
41
- if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
42
- install ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
43
- end
44
- end
45
-
46
- private
7
+ class << self
8
+ @@prepend = false
47
9
 
48
- def install(adapter)
49
- adapter.send(:include, ::ActiveRecord::Comments::ExecuteWithComments)
50
- end
10
+ def prepend=prepend
11
+ @@prepend = prepend
51
12
  end
52
- end
53
13
 
54
- class << self
55
14
  def comment(comment)
56
15
  current_comments << comment
57
16
  yield
@@ -61,7 +20,12 @@ module ActiveRecord
61
20
 
62
21
  def with_comment_sql(sql)
63
22
  return sql unless comment = current_comment
64
- "#{sql} /* #{comment} */"
23
+
24
+ if @@prepend == true
25
+ "/* #{comment} */ #{sql}"
26
+ else
27
+ "#{sql} /* #{comment} */"
28
+ end
65
29
  end
66
30
 
67
31
  private
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.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
27
33
  description:
28
34
  email: michael@grosser.it
29
35
  executables: []
@@ -32,6 +38,8 @@ extra_rdoc_files: []
32
38
  files:
33
39
  - MIT-LICENSE
34
40
  - lib/active_record/comments.rb
41
+ - lib/active_record/comments/execute_with_comments.rb
42
+ - lib/active_record/comments/version.rb
35
43
  homepage: https://github.com/grosser/active_record-comments
36
44
  licenses:
37
45
  - MIT
@@ -44,15 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
52
  requirements:
45
53
  - - ">="
46
54
  - !ruby/object:Gem::Version
47
- version: '0'
55
+ version: '2.7'
48
56
  required_rubygems_version: !ruby/object:Gem::Requirement
49
57
  requirements:
50
58
  - - ">="
51
59
  - !ruby/object:Gem::Version
52
60
  version: '0'
53
61
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.2.3
62
+ rubygems_version: 3.1.6
56
63
  signing_key:
57
64
  specification_version: 4
58
65
  summary: Comments for activerecord