activerecord-dowsing 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/ReleaseNote.md +16 -0
- data/activerecord-dowsing.gemspec +24 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/active_record/dowsing.rb +11 -0
- data/lib/active_record/dowsing/patch.rb +11 -0
- data/lib/active_record/dowsing/pg_connection_patch.rb +31 -0
- data/lib/active_record/dowsing/railtie.rb +22 -0
- data/lib/active_record/dowsing/util.rb +29 -0
- data/lib/active_record/dowsing/version.rb +5 -0
- data/lib/activerecord-dowsing.rb +1 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc18bba3486decc5bba5fd562bbfc0bed1319f46
|
4
|
+
data.tar.gz: 2f36e191cf3920cf25f72523be790f8c71bdbe0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5bb5500264c0601106c86aa76fa2529fd34de956462fac86afaa8618da4c71daed6c9e7353b9e8c5d1cd0b33e6e0458b1a20cb1bf0ba434a14b18a6fae72a34e
|
7
|
+
data.tar.gz: 6dff488ed55f0e464083f514f56198a7f75176225075a83d6cc9902dc9487de9a86adeb61f9594b156e6ac8d53f2085da3215b8b0b5369aec64f3dde95105476
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Activerecord::Dowsing
|
2
|
+
|
3
|
+
Add comment where is it called in your sql automatically. It's useful for code reading.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'activerecord-dowsing'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install activerecord-dowsing
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You can enable "activerecord-dowsing" by configuration.
|
24
|
+
|
25
|
+
config/application.rb
|
26
|
+
|
27
|
+
```
|
28
|
+
config.x.activerecord_dowsing.enabled = true
|
29
|
+
```
|
30
|
+
|
31
|
+
"activerecord-dowsing" changes all queries(with comment).
|
32
|
+
|
33
|
+
```
|
34
|
+
SELECT `id` FROM `users`
|
35
|
+
/* changes */
|
36
|
+
SELECT `id` FROM `users` /* /app/controllers/users_controller.rb:12:in `foo' */
|
37
|
+
```
|
38
|
+
|
39
|
+
If you want to mark for specific application, use `with_app_name` option.
|
40
|
+
|
41
|
+
```
|
42
|
+
config.x.activerecord_dowsing.with_app_name = true
|
43
|
+
```
|
44
|
+
|
45
|
+
```
|
46
|
+
SELECT `id` FROM `users`
|
47
|
+
/* changes */
|
48
|
+
SELECT `id` FROM `users` /* /app/controllers/users_controller.rb:12:in `foo'#app_name */
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
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.
|
data/Rakefile
ADDED
data/ReleaseNote.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# 1.0.0 : 2017/4/27
|
2
|
+
Remove: Drop configruration `activerecord_dowsing.enabled`. Please use `activerecord_dowsing.x.enabled` instead of.
|
3
|
+
Feature: Support postgresql
|
4
|
+
|
5
|
+
# 0.1.2 : 2016/1/22
|
6
|
+
Feature: Support configruration `activerecord_dowsing.enabled`
|
7
|
+
|
8
|
+
# 0.1.1 : 2016/1/22
|
9
|
+
|
10
|
+
Fix: Remove `require: 'active_record-dowsing'` in README. No need any more.(Fixed name)
|
11
|
+
Fix: Rewrite to modules.
|
12
|
+
Fix: Wrong test spec.
|
13
|
+
|
14
|
+
# 0.1.0 : 2016/1/21
|
15
|
+
|
16
|
+
First Release
|
@@ -0,0 +1,24 @@
|
|
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/dowsing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'activerecord-dowsing'
|
8
|
+
spec.version = ActiveRecord::Dowsing::VERSION
|
9
|
+
spec.authors = ['cyrill', 'alpaca-tc']
|
10
|
+
spec.email = ['siril.taka@gmail.com', 'alpaca-tc@alpaca.tc']
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.summary = %q{Mark tiny callers (stacktrace) in your sql.}
|
14
|
+
spec.description = %q{Add comment where is it called in your sql automatically. It's useful for code reading.}
|
15
|
+
spec.homepage = 'https://github.com/pixiv/activerecord-dowsing'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
spec.add_development_dependency 'activerecord', '~> 4.2'
|
24
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activerecord/dowsing"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_record/dowsing/version'
|
3
|
+
require 'active_record/dowsing/railtie'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Dowsing
|
7
|
+
autoload :Util, 'active_record/dowsing/util'
|
8
|
+
autoload :Patch, 'active_record/dowsing/patch'
|
9
|
+
autoload :PgConnectionPatch, 'active_record/dowsing/pg_connection_patch'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Dowsing
|
3
|
+
module PgConnectionPatch
|
4
|
+
# https://bitbucket.org/ged/ruby-pg/src/050a996456b14e1086581b79b391f37af999d414/ext/pg_connection.c?at=default&fileviewer=file-view-default
|
5
|
+
%i(
|
6
|
+
async_exec
|
7
|
+
exec_params
|
8
|
+
send_query
|
9
|
+
).each do |method_name|
|
10
|
+
module_eval(<<-INSERT_CALLER_LOCAION, __FILE__, __LINE__ + 1)
|
11
|
+
def #{method_name}(sql, *)
|
12
|
+
sql = Util.append_comment(sql)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
INSERT_CALLER_LOCAION
|
16
|
+
end
|
17
|
+
|
18
|
+
%i(
|
19
|
+
prepare
|
20
|
+
send_prepare
|
21
|
+
).each do |method_name|
|
22
|
+
module_eval(<<-INSERT_CALLER_LOCAION, __FILE__, __LINE__ + 1)
|
23
|
+
def #{method_name}(_, sql, *)
|
24
|
+
sql = Util.append_comment(sql)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
INSERT_CALLER_LOCAION
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Dowsing
|
3
|
+
class Railtie < ::Rails::Railtie
|
4
|
+
initializer 'ActiveRecord::Dowsing patch' do
|
5
|
+
next unless Rails.configuration.x.activerecord_dowsing.enabled
|
6
|
+
|
7
|
+
ActiveSupport.on_load :active_record do
|
8
|
+
configuration = ActiveRecord::Base.connection_config
|
9
|
+
resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({})
|
10
|
+
adapter_method = resolver.spec(configuration).adapter_method
|
11
|
+
adapter = ActiveRecord::Base.public_send(adapter_method, configuration)
|
12
|
+
|
13
|
+
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && adapter.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
14
|
+
PG::Connection.prepend(ActiveRecord::Dowsing::PgConnectionPatch)
|
15
|
+
elsif defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && adapter.is_a?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
16
|
+
adapter.class.prepend(ActiveRecord::Dowsing::Patch)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/core_ext/string/filters'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Dowsing
|
5
|
+
module Util
|
6
|
+
def self.append_comment(sql)
|
7
|
+
location = filter_stacktrace(caller).first
|
8
|
+
"#{sql} /* #{location}#{app_name} */"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.app_name
|
12
|
+
return unless Rails.application&.initialized? && Rails.configuration.x.activerecord_dowsing.with_app_name
|
13
|
+
"##{Rails.application.class.parent_name.downcase}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.filter_stacktrace(stack)
|
17
|
+
@cleaner ||= ActiveSupport::BacktraceCleaner.new.tap do |cleaner|
|
18
|
+
cleaner.add_filter { |line| line.remove(Rails.root.to_s) }
|
19
|
+
cleaner.add_filter { |line| line.remove('*') } # Sanitize comment
|
20
|
+
|
21
|
+
cleaner.add_silencer { |line| line =~ %r{activerecord-dowsing/lib} }
|
22
|
+
cleaner.add_silencer { |line| line =~ /gems/ }
|
23
|
+
end
|
24
|
+
|
25
|
+
@cleaner.clean(stack)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_record/dowsing'
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-dowsing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cyrill
|
8
|
+
- alpaca-tc
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.11'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.11'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: activerecord
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '4.2'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '4.2'
|
70
|
+
description: Add comment where is it called in your sql automatically. It's useful
|
71
|
+
for code reading.
|
72
|
+
email:
|
73
|
+
- siril.taka@gmail.com
|
74
|
+
- alpaca-tc@alpaca.tc
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".rspec"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- ReleaseNote.md
|
86
|
+
- activerecord-dowsing.gemspec
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/active_record/dowsing.rb
|
90
|
+
- lib/active_record/dowsing/patch.rb
|
91
|
+
- lib/active_record/dowsing/pg_connection_patch.rb
|
92
|
+
- lib/active_record/dowsing/railtie.rb
|
93
|
+
- lib/active_record/dowsing/util.rb
|
94
|
+
- lib/active_record/dowsing/version.rb
|
95
|
+
- lib/activerecord-dowsing.rb
|
96
|
+
homepage: https://github.com/pixiv/activerecord-dowsing
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.6.11
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Mark tiny callers (stacktrace) in your sql.
|
120
|
+
test_files: []
|