activerecord-commentator 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0adde2431f9bafcbb0d02dff9531fc7496c7e38d
4
+ data.tar.gz: 63d673b2db58b68ba95b71ec2bb84e8305e05af9
5
+ SHA512:
6
+ metadata.gz: 72f64658d81b4a17d444aa753fb43dda9902d58730525e90f8a49bd1e899033356e48ed11aa18a4ac5163d7845c293e208888617b5af8306987d564f32e32967
7
+ data.tar.gz: 7ab383e87ee05f736ddd6acc4afa4f7c406e54cb76e3fc9df3f059e665143dcd015c310c5b2b8e19dbd5e33d12107acb7ecef4c6cbe5cd35ab524af51f38eaef
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_record-commentator.gemspec
4
+ gemspec
@@ -0,0 +1,74 @@
1
+ # ActiveRecord::Commentator
2
+
3
+ ActiveRecord::Commentator adds `caller_location` (filename, line-number and method-name) as SQL comment that invokes SQL statement.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'activerecord-commentator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install activerecord-commentator
20
+
21
+ ## Usage
22
+
23
+ ### in Rails app
24
+
25
+ ```ruby
26
+ # in config/initializers/commentator.rb
27
+ require "active_record/commentator"
28
+
29
+ ActiveRecord::Commentator::Configuration.paths = [
30
+ /#{Rails.root.join("app").to_s}|#{Rails.root.join("lib").to_s}/
31
+ ]
32
+ ActiveRecord::Base.connection.class.prepend(ActiveRecord::Commentator)
33
+ ```
34
+
35
+ ### Start server and visit localhost:3000
36
+
37
+ ```
38
+ bundle exec rails server
39
+ ```
40
+
41
+ ## Rails application log
42
+
43
+ ```
44
+ # execute sql at model
45
+ (0.3ms) SELECT `favorites`.`product_id` FROM `favorites` /* /Users/hisaichi5518/projects/github.com/sample/app/models/product.rb:28:in `block in <class:Product>' */
46
+
47
+ # execute sql at view
48
+ Info Load (0.5ms) SELECT `infos`.* FROM `infos` /* /Users/hisaichi5518/projects/github.com/sample/app/cells/infos/index.html.erb:3:in `_app_cells_infos_index_html_erb___2113458239111152552_70242821135200' */
49
+ ```
50
+
51
+ ## Database slow log
52
+
53
+ ```
54
+ # Time: 198723 23:21:34
55
+ # User@Host: ... @ localhost []
56
+ # Query_time: 1.90872 Lock_time: 0.90879 Rows_sent: 1 Rows_examined: 9802714
57
+ ...
58
+ SELECT `favorites`.`product_id` FROM `favorites` /* /Users/hisaichi5518/projects/github.com/sample/app/models/product.rb:28:in `block in <class:Product>' */
59
+ ```
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hisaichi5518/activerecord-commentator.
70
+
71
+ ## See also
72
+
73
+ - https://github.com/joker1007/activerecord-cause
74
+ - https://metacpan.org/pod/DBIx::Sunny
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_record/commentator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord-commentator"
8
+ spec.version = ActiveRecord::Commentator::VERSION
9
+ spec.authors = ["hisaichi5518"]
10
+ spec.email = ["hisaichi5518@gmail.com"]
11
+
12
+ spec.summary = %q{adds `caller_location` as SQL comment}
13
+ spec.description = %q{ActiveRecord::Commentator adds execute location (filename, line-number and method-name) as SQL comment that invokes SQL statement.}
14
+ spec.homepage = "https://github.com/hisaichi5518/activerecord-commentator"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.1.6'
22
+
23
+ spec.add_runtime_dependency "activerecord", ">= 4.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "sqlite3"
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_record/commentator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require "active_record/commentator/version"
2
+ require "active_record/commentator/configuration"
3
+
4
+ module ActiveRecord
5
+ module Commentator
6
+ # ActiveRecord::ConnectionAdapters::DatabaseStatements#execute
7
+ def execute(sql, name = nil)
8
+ new_sql = write_comment_to_sql(sql, fetch_execute_location)
9
+ super(new_sql, name)
10
+ end
11
+
12
+ private
13
+ def fetch_execute_location
14
+ locations = caller_locations.select do |location|
15
+ ::ActiveRecord::Commentator::Configuration.paths.any? { |re| re.match(location.absolute_path) }
16
+ end
17
+
18
+ locations.first
19
+ end
20
+
21
+ def write_comment_to_sql(sql, comment)
22
+ return sql unless comment
23
+ sql + " /* #{comment.to_s.chomp} */ "
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require "active_support/configurable"
2
+
3
+ module ActiveRecord
4
+ module Commentator
5
+ module Configuration
6
+ include ActiveSupport::Configurable
7
+
8
+ config_accessor :paths, instance_accessor: false do
9
+ []
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module Commentator
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-commentator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hisaichi5518
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ActiveRecord::Commentator adds execute location (filename, line-number
84
+ and method-name) as SQL comment that invokes SQL statement.
85
+ email:
86
+ - hisaichi5518@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - activerecord-commentator.gemspec
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/active_record/commentator.rb
101
+ - lib/active_record/commentator/configuration.rb
102
+ - lib/active_record/commentator/version.rb
103
+ homepage: https://github.com/hisaichi5518/activerecord-commentator
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 2.1.6
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: adds `caller_location` as SQL comment
126
+ test_files: []