rails_sql_counter 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rails_sql_counter.rb +54 -0
- data/lib/rails_sql_counter/version.rb +3 -0
- data/rails_sql_counter.gemspec +23 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5bbc30585158b380077f576278e1cbc18ed380793af58e0520f3d843647d8714
|
4
|
+
data.tar.gz: 9293aababdf01166e3b96b179531e0666efe044fbbd78e95c2f9953d95fc2c3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23b0c23659a1b376cb10c62b79313026e9e5da34b85cb00cb8a09757bf810b8e75e11324657313935dd5f81bbe3142ac28d20d8114204158a6d85755149d1da0
|
7
|
+
data.tar.gz: d6e364fdfa43a107eff3330d2788786aca3baf0bed37c829b766a07b45e734475136dc33a178d380be2e960e4c30542e60c4d98add0efd4fb9d95fd5d76defac
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.1.0] - 2021-08-17
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- First version
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails_sql_counter (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (12.3.3)
|
11
|
+
rspec (3.10.0)
|
12
|
+
rspec-core (~> 3.10.0)
|
13
|
+
rspec-expectations (~> 3.10.0)
|
14
|
+
rspec-mocks (~> 3.10.0)
|
15
|
+
rspec-core (3.10.1)
|
16
|
+
rspec-support (~> 3.10.0)
|
17
|
+
rspec-expectations (3.10.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.10.0)
|
20
|
+
rspec-mocks (3.10.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-support (3.10.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
rails_sql_counter!
|
30
|
+
rake (~> 12.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 rjurado
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# RailsSqlCounter
|
2
|
+
|
3
|
+
Keep under control how many sql queries are launched in your App
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rails_sql_counter'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rails_sql_counter
|
20
|
+
|
21
|
+
## Doc
|
22
|
+
|
23
|
+
### Configuration
|
24
|
+
|
25
|
+
* **backtrace**: activates / desactivates sql query backtrace
|
26
|
+
* **backtrace_regex**: allows to ignore lines from backtrace (line is ignore if it match)
|
27
|
+
|
28
|
+
### Methods
|
29
|
+
|
30
|
+
* **start**: starts to count sql queries
|
31
|
+
* **end**: ends to count sql queries
|
32
|
+
* **counter**: returns number of sql quieries from start
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Test example:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
context '...' do
|
40
|
+
before { RailsSqlCounter.start }
|
41
|
+
after { RailsSqlCounter.end }
|
42
|
+
|
43
|
+
it 'returns results with only one query' do
|
44
|
+
get path
|
45
|
+
|
46
|
+
expect(RailsSqlCounter.counter).to eq(1)
|
47
|
+
end
|
48
|
+
end
|
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 to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_sql_counter.
|
60
|
+
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rails_sql_counter"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_sql_counter/version'
|
4
|
+
|
5
|
+
# Count sql queries
|
6
|
+
module RailsSqlCounter
|
7
|
+
mattr_accessor :backtrace, default: false
|
8
|
+
mattr_accessor :backtrace_regex, default: /(action|active|pry|rack|puma|rspec|bundle)/
|
9
|
+
|
10
|
+
def self.setup
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.process(event)
|
15
|
+
return unless event.payload[:name]&.match?('Load') && Thread.current[:rails_sql_counter]
|
16
|
+
|
17
|
+
inc
|
18
|
+
show_backtrace if @@backtrace
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.inc
|
22
|
+
Thread.current[:rails_sql_counter] += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.start
|
26
|
+
Thread.current[:rails_sql_counter] = 0
|
27
|
+
|
28
|
+
@@subscriber ||= ActiveSupport::Notifications.subscribe('sql.active_record') do |event|
|
29
|
+
process(event)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.end
|
34
|
+
Thread.current[:rails_sql_counter] = nil
|
35
|
+
|
36
|
+
ActiveSupport::Notifications.unsubscribe(@@subscriber)
|
37
|
+
@@subscriber = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.counter
|
41
|
+
Thread.current[:rails_sql_counter]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.show_backtrace
|
45
|
+
# remove first two entries (gem entries)
|
46
|
+
caller.drop(2).each do |line|
|
47
|
+
next if line.match?(@@backtrace_regex)
|
48
|
+
|
49
|
+
Rails.logger.debug " -> #{line}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private_class_method :inc, :show_backtrace
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'lib/rails_sql_counter/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'rails_sql_counter'
|
5
|
+
spec.version = RailsSqlCounter::VERSION
|
6
|
+
spec.authors = ['rjurado']
|
7
|
+
spec.email = ['rjurado@nosolosoftware.es']
|
8
|
+
|
9
|
+
spec.summary = 'Keep under control how many sql queries are launched in your App'
|
10
|
+
spec.description = 'Allows to control how many queries are launched between two points'
|
11
|
+
spec.homepage = 'https://github.com/nosolosoftware/rails_sql_counter'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_sql_counter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rjurado
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Allows to control how many queries are launched between two points
|
14
|
+
email:
|
15
|
+
- rjurado@nosolosoftware.es
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- lib/rails_sql_counter.rb
|
31
|
+
- lib/rails_sql_counter/version.rb
|
32
|
+
- rails_sql_counter.gemspec
|
33
|
+
homepage: https://github.com/nosolosoftware/rails_sql_counter
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.4
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Keep under control how many sql queries are launched in your App
|
56
|
+
test_files: []
|