active_record-comments 0.0.1

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/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - ree
3
+ - 1.9.3
4
+ gemfile:
5
+ - gemfiles/activerecord_2.3.gemfile
6
+ - gemfiles/activerecord_3.0.gemfile
7
+ - gemfiles/activerecord_3.1.gemfile
8
+ - gemfiles/activerecord_3.2.gemfile
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ ["2.3", "3.0", "3.1", "3.2"].each do |version|
2
+ appraise "activerecord_#{version}" do
3
+ gem "activerecord", "~> #{version}.0"
4
+ end
5
+ end
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ gem "appraisal"
5
+ gem "bump"
6
+ gem "rake"
7
+ gem "rspec", "~>2"
8
+ gem "sqlite3"
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_record-comments (0.0.1)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.11)
11
+ activesupport (= 3.2.11)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
+ arel (~> 3.0.2)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.11)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ appraisal (0.5.1)
22
+ bundler
23
+ rake
24
+ arel (3.0.2)
25
+ builder (3.0.4)
26
+ bump (0.3.8)
27
+ diff-lcs (1.1.3)
28
+ i18n (0.6.1)
29
+ multi_json (1.5.0)
30
+ rake (0.9.2)
31
+ rspec (2.6.0)
32
+ rspec-core (~> 2.6.0)
33
+ rspec-expectations (~> 2.6.0)
34
+ rspec-mocks (~> 2.6.0)
35
+ rspec-core (2.6.4)
36
+ rspec-expectations (2.6.0)
37
+ diff-lcs (~> 1.1.2)
38
+ rspec-mocks (2.6.0)
39
+ sqlite3 (1.3.6)
40
+ tzinfo (0.3.35)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ active_record-comments!
47
+ appraisal
48
+ bump
49
+ rake
50
+ rspec (~> 2)
51
+ sqlite3
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "bump/tasks"
3
+ require "appraisal"
4
+
5
+ task :spec do
6
+ sh "rspec spec/"
7
+ end
8
+
9
+ task :default do
10
+ sh "bundle exec rake appraisal:install && bundle exec rake appraisal spec"
11
+ end
data/Readme.md ADDED
@@ -0,0 +1,27 @@
1
+ Adds comments to your activerecord queries so you can seem where they came from or what user caused them.<br/>
2
+ for on Rails 2 + 3 + 4
3
+
4
+ Install
5
+ =======
6
+
7
+ gem install active_record-comments
8
+
9
+ Usage
10
+ =====
11
+
12
+ require "active_record/comments"
13
+
14
+ # => SELECT ... /* user.rb:123 */
15
+ result = ActiveRecord::Comments.comment("user.rb:123"){ User.where("x like y").count }
16
+
17
+ # => SELECT ... /* account cleanup initial */
18
+ result = ActiveRecord::Comments.comment("account cleanup") do
19
+ ActiveRecord::Comments.comment("initial"){ User.where("x like y").count }
20
+ end
21
+
22
+ Author
23
+ ======
24
+ [Michael Grosser](http://grosser.it)<br/>
25
+ michael@grosser.it<br/>
26
+ License: MIT<br/>
27
+ [![Build Status](https://travis-ci.org/grosser/active_record-comments.png)](https://travis-ci.org/grosser/active_record-comments)
@@ -0,0 +1,11 @@
1
+ name = "active_record-comments"
2
+
3
+ Gem::Specification.new name, "0.0.1" do |s|
4
+ s.summary = "Comments for activerecord"
5
+ s.authors = ["Michael Grosser"]
6
+ s.email = "michael@grosser.it"
7
+ s.homepage = "http://github.com/grosser/#{name}"
8
+ s.files = `git ls-files`.split("\n")
9
+ s.license = "MIT"
10
+ s.add_runtime_dependency "activerecord"
11
+ end
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "bump"
7
+ gem "rake"
8
+ gem "rspec", "~>2"
9
+ gem "sqlite3"
10
+ gem "activerecord", "~> 2.3.0"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/active_record-comments
3
+ specs:
4
+ active_record-comments (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activerecord (2.3.15)
11
+ activesupport (= 2.3.15)
12
+ activesupport (2.3.15)
13
+ appraisal (0.5.1)
14
+ bundler
15
+ rake
16
+ bump (0.3.9)
17
+ diff-lcs (1.1.3)
18
+ rake (10.0.3)
19
+ rspec (2.12.0)
20
+ rspec-core (~> 2.12.0)
21
+ rspec-expectations (~> 2.12.0)
22
+ rspec-mocks (~> 2.12.0)
23
+ rspec-core (2.12.2)
24
+ rspec-expectations (2.12.1)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.12.1)
27
+ sqlite3 (1.3.7)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ active_record-comments!
34
+ activerecord (~> 2.3.0)
35
+ appraisal
36
+ bump
37
+ rake
38
+ rspec (~> 2)
39
+ sqlite3
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "bump"
7
+ gem "rake"
8
+ gem "rspec", "~>2"
9
+ gem "sqlite3"
10
+ gem "activerecord", "~> 3.0.0"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/active_record-comments
3
+ specs:
4
+ active_record-comments (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.0.19)
11
+ activesupport (= 3.0.19)
12
+ builder (~> 2.1.2)
13
+ i18n (~> 0.5.0)
14
+ activerecord (3.0.19)
15
+ activemodel (= 3.0.19)
16
+ activesupport (= 3.0.19)
17
+ arel (~> 2.0.10)
18
+ tzinfo (~> 0.3.23)
19
+ activesupport (3.0.19)
20
+ appraisal (0.5.1)
21
+ bundler
22
+ rake
23
+ arel (2.0.10)
24
+ builder (2.1.2)
25
+ bump (0.3.9)
26
+ diff-lcs (1.1.3)
27
+ i18n (0.5.0)
28
+ rake (10.0.3)
29
+ rspec (2.12.0)
30
+ rspec-core (~> 2.12.0)
31
+ rspec-expectations (~> 2.12.0)
32
+ rspec-mocks (~> 2.12.0)
33
+ rspec-core (2.12.2)
34
+ rspec-expectations (2.12.1)
35
+ diff-lcs (~> 1.1.3)
36
+ rspec-mocks (2.12.1)
37
+ sqlite3 (1.3.7)
38
+ tzinfo (0.3.35)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ active_record-comments!
45
+ activerecord (~> 3.0.0)
46
+ appraisal
47
+ bump
48
+ rake
49
+ rspec (~> 2)
50
+ sqlite3
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "bump"
7
+ gem "rake"
8
+ gem "rspec", "~>2"
9
+ gem "sqlite3"
10
+ gem "activerecord", "~> 3.1.0"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/active_record-comments
3
+ specs:
4
+ active_record-comments (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.1.10)
11
+ activesupport (= 3.1.10)
12
+ builder (~> 3.0.0)
13
+ i18n (~> 0.6)
14
+ activerecord (3.1.10)
15
+ activemodel (= 3.1.10)
16
+ activesupport (= 3.1.10)
17
+ arel (~> 2.2.3)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.1.10)
20
+ multi_json (>= 1.0, < 1.3)
21
+ appraisal (0.5.1)
22
+ bundler
23
+ rake
24
+ arel (2.2.3)
25
+ builder (3.0.4)
26
+ bump (0.3.9)
27
+ diff-lcs (1.1.3)
28
+ i18n (0.6.1)
29
+ multi_json (1.2.0)
30
+ rake (10.0.3)
31
+ rspec (2.12.0)
32
+ rspec-core (~> 2.12.0)
33
+ rspec-expectations (~> 2.12.0)
34
+ rspec-mocks (~> 2.12.0)
35
+ rspec-core (2.12.2)
36
+ rspec-expectations (2.12.1)
37
+ diff-lcs (~> 1.1.3)
38
+ rspec-mocks (2.12.1)
39
+ sqlite3 (1.3.7)
40
+ tzinfo (0.3.35)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ active_record-comments!
47
+ activerecord (~> 3.1.0)
48
+ appraisal
49
+ bump
50
+ rake
51
+ rspec (~> 2)
52
+ sqlite3
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source :rubygems
4
+
5
+ gem "appraisal"
6
+ gem "bump"
7
+ gem "rake"
8
+ gem "rspec", "~>2"
9
+ gem "sqlite3"
10
+ gem "activerecord", "~> 3.2.0"
11
+
12
+ gemspec :path=>"../"
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: /Users/mgrosser/code/tools/active_record-comments
3
+ specs:
4
+ active_record-comments (0.0.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.11)
11
+ activesupport (= 3.2.11)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
+ arel (~> 3.0.2)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.11)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ appraisal (0.5.1)
22
+ bundler
23
+ rake
24
+ arel (3.0.2)
25
+ builder (3.0.4)
26
+ bump (0.3.9)
27
+ diff-lcs (1.1.3)
28
+ i18n (0.6.1)
29
+ multi_json (1.5.0)
30
+ rake (10.0.3)
31
+ rspec (2.12.0)
32
+ rspec-core (~> 2.12.0)
33
+ rspec-expectations (~> 2.12.0)
34
+ rspec-mocks (~> 2.12.0)
35
+ rspec-core (2.12.2)
36
+ rspec-expectations (2.12.1)
37
+ diff-lcs (~> 1.1.3)
38
+ rspec-mocks (2.12.1)
39
+ sqlite3 (1.3.7)
40
+ tzinfo (0.3.35)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ active_record-comments!
47
+ activerecord (~> 3.2.0)
48
+ appraisal
49
+ bump
50
+ rake
51
+ rspec (~> 2)
52
+ sqlite3
@@ -0,0 +1,55 @@
1
+ require "active_record"
2
+
3
+ module ActiveRecord
4
+ module Comments
5
+ class << self
6
+ def comment(comment)
7
+ @comment ||= []
8
+ @comment << comment
9
+ yield
10
+ ensure
11
+ @comment.pop
12
+ end
13
+
14
+ def with_comment_sql(sql)
15
+ return sql unless comment = current_comment
16
+ "#{sql} /* #{comment} */"
17
+ end
18
+
19
+ private
20
+
21
+ def current_comment
22
+ @comment.join(" ") if @comment.present?
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ if ActiveRecord::VERSION::MAJOR == 2
29
+ class << ActiveRecord::Base
30
+ def construct_finder_sql_with_comments(options)
31
+ sql = construct_finder_sql_without_comments(options)
32
+ ActiveRecord::Comments.with_comment_sql(sql)
33
+ end
34
+ alias_method_chain(:construct_finder_sql, :comments)
35
+
36
+ def construct_calculation_sql_with_comments(operation, column_name, options)
37
+ sql = construct_calculation_sql_without_comments(operation, column_name, options)
38
+ ActiveRecord::Comments.with_comment_sql(sql)
39
+ end
40
+ alias_method_chain(:construct_calculation_sql, :comments)
41
+ end
42
+ else
43
+ klass = if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
44
+ Arel::SelectManager
45
+ else
46
+ ActiveRecord::Relation
47
+ end
48
+
49
+ klass.class_eval do
50
+ alias to_sql_with_comments to_sql
51
+ def to_sql
52
+ ActiveRecord::Comments.with_comment_sql(to_sql_with_comments)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+
3
+ describe ActiveRecord::Comments do
4
+ def normalize_sql(sql)
5
+ sql.gsub("``", '""').gsub(" ", " ").strip
6
+ end
7
+
8
+ describe ".current_comment" do
9
+ it "be empty when not called" do
10
+ ActiveRecord::Comments.comment("xxx"){}
11
+ ActiveRecord::Comments.send(:current_comment).should == nil
12
+ end
13
+
14
+ it "be filled when called" do
15
+ result = nil
16
+ ActiveRecord::Comments.comment("xxx") do
17
+ result = ActiveRecord::Comments.send(:current_comment)
18
+ end
19
+ "xxx".should == result
20
+ end
21
+
22
+ it "concat" do
23
+ result = nil
24
+ ActiveRecord::Comments.comment("xxx") do
25
+ ActiveRecord::Comments.comment("yyy") do
26
+ result = ActiveRecord::Comments.send(:current_comment)
27
+ end
28
+ end
29
+ result.should == "xxx yyy"
30
+ end
31
+
32
+ it "unpop" do
33
+ result = nil
34
+ ActiveRecord::Comments.comment("xxx") do
35
+ ActiveRecord::Comments.comment("yyy") { }
36
+ result = ActiveRecord::Comments.send(:current_comment)
37
+ end
38
+ result.should == "xxx"
39
+ end
40
+ end
41
+
42
+ describe ".comment" do
43
+ it "return results" do
44
+ ActiveRecord::Comments.comment("xxx"){ 1 }.should == 1
45
+ end
46
+ end
47
+
48
+ if ActiveRecord::VERSION::MAJOR == 2
49
+ describe "#construct_finder_sql" do
50
+ it "not be there when not called" do
51
+ ActiveRecord::Comments.comment("xxx"){ }
52
+ normalize_sql(User.scoped(:conditions => {:id => 1}).send(:construct_finder_sql, {})).should ==
53
+ 'SELECT * FROM "users" WHERE ("users"."id" = 1)'
54
+ end
55
+
56
+ it "be there when called" do
57
+ result = nil
58
+ ActiveRecord::Comments.comment("xxx") do
59
+ result = User.scoped(:conditions => {:id => 1}).send(:construct_finder_sql, {})
60
+ end
61
+ normalize_sql(result).should == 'SELECT * FROM "users" WHERE ("users"."id" = 1) /* xxx */'
62
+ end
63
+ end
64
+
65
+ describe "#construct_calculation_sql_with_comments" do
66
+ it "not be there when not called" do
67
+ ActiveRecord::Comments.comment("xxx"){ }
68
+ normalize_sql(User.scoped(:conditions => {:id => 1}).send(:construct_calculation_sql_with_comments, "count", "id", {})).should ==
69
+ 'SELECT count("users".id) AS count_id FROM "users" WHERE ("users"."id" = 1)'
70
+ end
71
+
72
+ it "be there when called" do
73
+ result = nil
74
+ ActiveRecord::Comments.comment("xxx") do
75
+ result = User.scoped(:conditions => {:id => 1}).send(:construct_calculation_sql_with_comments, "count", "id", {})
76
+ end
77
+ normalize_sql(result).should == 'SELECT count("users".id) AS count_id FROM "users" WHERE ("users"."id" = 1) /* xxx */'
78
+ end
79
+ end
80
+ else
81
+ describe "#to_sql" do
82
+ it "not be there when not called" do
83
+ ActiveRecord::Comments.comment("xxx"){ }
84
+ normalize_sql(User.where(:id => 1).to_sql).should == 'SELECT "users".* FROM "users" WHERE "users"."id" = 1'
85
+ end
86
+
87
+ it "be there when called" do
88
+ result = nil
89
+ ActiveRecord::Comments.comment("xxx") do
90
+ result = User.where(:id => 1).to_sql
91
+ end
92
+ normalize_sql(result).should == 'SELECT "users".* FROM "users" WHERE "users"."id" = 1 /* xxx */'
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,16 @@
1
+ require "active_record/comments"
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ :adapter => "sqlite3",
5
+ :database => ":memory:"
6
+ )
7
+
8
+ ActiveRecord::Schema.verbose = false
9
+ ActiveRecord::Schema.define(:version => 1) do
10
+ create_table :users do |t|
11
+ t.string :name
12
+ end
13
+ end
14
+
15
+ class User < ActiveRecord::Base
16
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record-comments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Grosser
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description:
31
+ email: michael@grosser.it
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .travis.yml
37
+ - Appraisals
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - Rakefile
41
+ - Readme.md
42
+ - active_record-comments.gemspec
43
+ - gemfiles/activerecord_2.3.gemfile
44
+ - gemfiles/activerecord_2.3.gemfile.lock
45
+ - gemfiles/activerecord_3.0.gemfile
46
+ - gemfiles/activerecord_3.0.gemfile.lock
47
+ - gemfiles/activerecord_3.1.gemfile
48
+ - gemfiles/activerecord_3.1.gemfile.lock
49
+ - gemfiles/activerecord_3.2.gemfile
50
+ - gemfiles/activerecord_3.2.gemfile.lock
51
+ - lib/active_record/comments.rb
52
+ - spec/active_record/comments_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: http://github.com/grosser/active_record-comments
55
+ licenses:
56
+ - MIT
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: -2889031802467512839
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: -2889031802467512839
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.24
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Comments for activerecord
85
+ test_files: []