bullet 5.5.0 → 6.1.5

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.
Files changed (123) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +66 -0
  3. data/CHANGELOG.md +83 -1
  4. data/Gemfile +6 -1
  5. data/Gemfile.mongoid-7.0 +15 -0
  6. data/Gemfile.rails-4.0 +1 -1
  7. data/Gemfile.rails-4.1 +1 -1
  8. data/Gemfile.rails-4.2 +1 -1
  9. data/Gemfile.rails-5.0 +2 -2
  10. data/Gemfile.rails-5.1 +15 -0
  11. data/Gemfile.rails-5.2 +15 -0
  12. data/Gemfile.rails-6.0 +15 -0
  13. data/Gemfile.rails-6.1 +15 -0
  14. data/Guardfile +2 -2
  15. data/Hacking.md +1 -1
  16. data/README.md +58 -37
  17. data/Rakefile +20 -21
  18. data/bullet.gemspec +21 -15
  19. data/lib/bullet/active_job.rb +13 -0
  20. data/lib/bullet/active_record4.rb +15 -34
  21. data/lib/bullet/active_record41.rb +14 -31
  22. data/lib/bullet/active_record42.rb +23 -36
  23. data/lib/bullet/active_record5.rb +178 -158
  24. data/lib/bullet/active_record52.rb +251 -0
  25. data/lib/bullet/active_record60.rb +278 -0
  26. data/lib/bullet/active_record61.rb +278 -0
  27. data/lib/bullet/bullet_xhr.js +64 -0
  28. data/lib/bullet/dependency.rb +60 -32
  29. data/lib/bullet/detector/association.rb +41 -32
  30. data/lib/bullet/detector/base.rb +2 -0
  31. data/lib/bullet/detector/counter_cache.rb +25 -17
  32. data/lib/bullet/detector/n_plus_one_query.rb +38 -24
  33. data/lib/bullet/detector/unused_eager_loading.rb +35 -26
  34. data/lib/bullet/detector.rb +2 -0
  35. data/lib/bullet/ext/object.rb +9 -5
  36. data/lib/bullet/ext/string.rb +3 -1
  37. data/lib/bullet/mongoid4x.rb +9 -8
  38. data/lib/bullet/mongoid5x.rb +9 -8
  39. data/lib/bullet/mongoid6x.rb +13 -12
  40. data/lib/bullet/mongoid7x.rb +57 -0
  41. data/lib/bullet/notification/base.rb +28 -25
  42. data/lib/bullet/notification/counter_cache.rb +3 -1
  43. data/lib/bullet/notification/n_plus_one_query.rb +8 -7
  44. data/lib/bullet/notification/unused_eager_loading.rb +8 -7
  45. data/lib/bullet/notification.rb +4 -1
  46. data/lib/bullet/notification_collector.rb +2 -1
  47. data/lib/bullet/rack.rb +66 -35
  48. data/lib/bullet/registry/association.rb +2 -0
  49. data/lib/bullet/registry/base.rb +2 -0
  50. data/lib/bullet/registry/object.rb +2 -0
  51. data/lib/bullet/registry.rb +2 -0
  52. data/lib/bullet/stack_trace_filter.rb +50 -20
  53. data/lib/bullet/version.rb +3 -2
  54. data/lib/bullet.rb +136 -55
  55. data/lib/generators/bullet/install_generator.rb +48 -0
  56. data/perf/benchmark.rb +19 -22
  57. data/rails/init.rb +2 -0
  58. data/spec/bullet/detector/association_spec.rb +6 -4
  59. data/spec/bullet/detector/base_spec.rb +2 -0
  60. data/spec/bullet/detector/counter_cache_spec.rb +17 -15
  61. data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
  62. data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
  63. data/spec/bullet/ext/object_spec.rb +18 -11
  64. data/spec/bullet/ext/string_spec.rb +7 -5
  65. data/spec/bullet/notification/base_spec.rb +38 -39
  66. data/spec/bullet/notification/counter_cache_spec.rb +5 -3
  67. data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
  68. data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
  69. data/spec/bullet/notification_collector_spec.rb +12 -10
  70. data/spec/bullet/rack_spec.rb +200 -48
  71. data/spec/bullet/registry/association_spec.rb +12 -10
  72. data/spec/bullet/registry/base_spec.rb +22 -20
  73. data/spec/bullet/registry/object_spec.rb +6 -4
  74. data/spec/bullet_spec.rb +64 -33
  75. data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
  76. data/spec/integration/counter_cache_spec.rb +26 -44
  77. data/spec/integration/mongoid/association_spec.rb +53 -65
  78. data/spec/models/address.rb +2 -0
  79. data/spec/models/attachment.rb +5 -0
  80. data/spec/models/author.rb +2 -0
  81. data/spec/models/base_user.rb +2 -0
  82. data/spec/models/category.rb +2 -0
  83. data/spec/models/city.rb +2 -0
  84. data/spec/models/client.rb +4 -0
  85. data/spec/models/comment.rb +3 -1
  86. data/spec/models/company.rb +2 -0
  87. data/spec/models/country.rb +2 -0
  88. data/spec/models/deal.rb +5 -0
  89. data/spec/models/document.rb +4 -2
  90. data/spec/models/entry.rb +2 -0
  91. data/spec/models/firm.rb +3 -0
  92. data/spec/models/folder.rb +2 -0
  93. data/spec/models/group.rb +4 -0
  94. data/spec/models/mongoid/address.rb +3 -1
  95. data/spec/models/mongoid/category.rb +4 -2
  96. data/spec/models/mongoid/comment.rb +3 -1
  97. data/spec/models/mongoid/company.rb +3 -1
  98. data/spec/models/mongoid/entry.rb +3 -1
  99. data/spec/models/mongoid/post.rb +6 -4
  100. data/spec/models/mongoid/user.rb +2 -0
  101. data/spec/models/newspaper.rb +3 -1
  102. data/spec/models/page.rb +2 -0
  103. data/spec/models/person.rb +2 -0
  104. data/spec/models/pet.rb +2 -0
  105. data/spec/models/post.rb +19 -0
  106. data/spec/models/relationship.rb +2 -0
  107. data/spec/models/reply.rb +2 -0
  108. data/spec/models/student.rb +2 -0
  109. data/spec/models/submission.rb +3 -0
  110. data/spec/models/teacher.rb +2 -0
  111. data/spec/models/user.rb +3 -0
  112. data/spec/models/writer.rb +2 -0
  113. data/spec/spec_helper.rb +19 -23
  114. data/spec/support/bullet_ext.rb +10 -9
  115. data/spec/support/mongo_seed.rb +38 -57
  116. data/spec/support/rack_double.rb +13 -19
  117. data/spec/support/sqlite_seed.rb +104 -76
  118. data/tasks/bullet_tasks.rake +4 -2
  119. data/test.sh +5 -0
  120. data/update.sh +3 -0
  121. metadata +34 -17
  122. data/.travis.yml +0 -16
  123. data/spec/integration/active_record5/association_spec.rb +0 -768
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7f8cac0418ea4a1bb9f8abc6c12e84022f2f118d
4
- data.tar.gz: ebdf99115037dec22a5480a63d3bed5f15956dda
2
+ SHA256:
3
+ metadata.gz: b21c2c4ca3caf6c41961a7182a5c8d37f6b89aa78b8dfb7badfb940f11a23191
4
+ data.tar.gz: 0f432034f9b4cb2fe6c6572481c797aefcfa69373839fbd0985a7efd2a0bbea9
5
5
  SHA512:
6
- metadata.gz: 0904f996964a403a495af310bab8a0612e614eb72a71d08646948508c25d4bf36d2b939da65156a5fc81595477820e0f123aa2a88d618fe97e28e81a6b6f8ada
7
- data.tar.gz: d491e12ccce38a26a5e3d27d3f6b84acafe34bb7b6aff56b78a8e22a73a5a3abf88443110587de0080e50b32ef70d8ca387eab5faac0b1bec16efed04bf3acc1
6
+ metadata.gz: d2457987f11f034fa457030cf7161d7508fb26230cf9e88a2571c54a934ad9a1330b48dd3d38eede3033bd7ef6c920e564dcbfa43a15354bf72d14ed799aefe2
7
+ data.tar.gz: ed6690fcb3bd778d6d5a27538a0ee78d298c749be1e445c305b9884448ca13f97e5a62c76ac48229a250041bb09ba609d6b154b12cf42a0f3dca66fbb9c83021
@@ -0,0 +1,66 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test_rails_4:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ gemfile: ['Gemfile.rails-4.0', 'Gemfile.rails-4.1', 'Gemfile.rails-4.2']
22
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
23
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: 2.3
30
+ bundler: 1
31
+ bundler-cache: true
32
+ - name: Run tests
33
+ run: bundle exec rake
34
+ test_rails_5:
35
+ runs-on: ubuntu-latest
36
+ strategy:
37
+ matrix:
38
+ gemfile: ['Gemfile.rails-5.0', 'Gemfile.rails-5.1', 'Gemfile.rails-5.2']
39
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
40
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
41
+ steps:
42
+ - uses: actions/checkout@v2
43
+ - name: Set up Ruby
44
+ uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: 2.5
47
+ bundler: 1
48
+ bundler-cache: true
49
+ - name: Run tests
50
+ run: bundle exec rake
51
+ test_rails_6:
52
+ runs-on: ubuntu-latest
53
+ strategy:
54
+ matrix:
55
+ gemfile: ['Gemfile.rails-6.0', 'Gemfile.rails-6.1']
56
+ env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
57
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
58
+ steps:
59
+ - uses: actions/checkout@v2
60
+ - name: Set up Ruby
61
+ uses: ruby/setup-ruby@v1
62
+ with:
63
+ ruby-version: 2.7
64
+ bundler-cache: true
65
+ - name: Run tests
66
+ run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,4 +1,86 @@
1
- # Next Release
1
+ ## Next Release
2
+
3
+ ## 6.1.5 (08/16/2021)
4
+
5
+ * Rename whitelist to safelist
6
+ * Fix onload called twice
7
+ * Support Rack::Files::Iterator responses
8
+ * Ensure HABTM associations are not incorrectly labeled n+1
9
+
10
+ ## 6.1.4 (02/26/2021)
11
+
12
+ * Added an option to stop adding HTTP headers to API requests
13
+
14
+ ## 6.1.3 (01/21/2021)
15
+
16
+ * Consider ThroughAssociation at SingularAssociation like CollectionAssociation
17
+ * Add xhr_script only when add_footer is enabled
18
+
19
+ ## 6.1.2 (12/12/2020)
20
+
21
+ * Revert "Make whitelist thread safe"
22
+
23
+ ## 6.1.1 (12/12/2020)
24
+
25
+ * Add support Rails 6.1
26
+ * Make whitelist thread safe
27
+
28
+ ## 6.1.0 (12/28/2019)
29
+
30
+ * Add skip_html_injection flag
31
+ * Remove writer hack in active_record6
32
+ * Use modern includes syntax in warnings
33
+ * Fix warning: The last argument is used as the keyword parameter
34
+
35
+ ## 6.0.2 (08/20/2019)
36
+
37
+ * Fully support Rails 6.0
38
+
39
+ ## 6.0.1 (06/26/2019)
40
+
41
+ * Add Bullet::ActiveJob
42
+ * Prevent "Maximum call stack exceeded" errors when used with Turbolinks
43
+
44
+ ## 6.0.0 (04/25/2019)
45
+
46
+ * Add XHR support to Bullet
47
+ * Support Rails 6.0
48
+ * Handle case where ID is manually set on unpersisted record
49
+
50
+ ## 5.9.0 (11/11/2018)
51
+
52
+ * Require Ruby 2.3+
53
+ * Support Mongo 7.x
54
+
55
+ ## 5.8.0 (10/29/2018)
56
+
57
+ * Fix through reflection for rails 5.x
58
+ * Fix false positive in after_save/after_create callbacks
59
+ * Don't triger a preload error on "manual" preloads
60
+ * Avoid Bullet from making extra queries in mongoid6
61
+ * Support option for #first and #last on mongoid6.x
62
+ * Fix duplicate logs in mongoid 4.x and 5.x version
63
+ * Use caller for ruby 1.9 while caller_locations for 2.0+
64
+ * Extend stacktrace matching for sub-file precision
65
+ * Exclude configured bundler path in addition to '/vendor'
66
+ * Fix `caller_path` in `excluded_stacktrace_path`
67
+ * Update `uniform_notifier` dependency to add Sentry support
68
+ * Integrate awesomecode.io and refactor code
69
+
70
+ ## 5.7.0 (12/03/2017)
71
+
72
+ * Support rails 5.2
73
+ * Implement Bullet.delete_whitelist to delete a specific whitelist definition
74
+ * Fix caller_path in the case of nil
75
+
76
+ ## 5.6.0 (07/16/2017)
77
+
78
+ * Migrate alias_method to Module#prepend
79
+ * Add install generator
80
+ * Stack trace filter
81
+ * Fix rails 5.1 compatibility
82
+ * Fix inverse_of for rails 5
83
+ * Fix detect file attachment for rack #319
2
84
 
3
85
  ## 5.5.0 (12/30/2016)
4
86
 
data/Gemfile CHANGED
@@ -1,8 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
3
8
  gemspec
4
9
 
5
- gem 'rails', github: 'rails/rails'
10
+ gem 'rails', github: 'rails'
6
11
  gem 'sqlite3', platforms: [:ruby]
7
12
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
13
  gem 'activerecord-import'
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.0'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mongoid', '~> 7.0.0'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/Gemfile.rails-4.0 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.0.0'
6
- gem 'sqlite3', platforms: [:ruby]
6
+ gem 'sqlite3', '~> 1.3.6', platforms: [:ruby]
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
data/Gemfile.rails-4.1 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
data/Gemfile.rails-4.2 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.2.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
data/Gemfile.rails-5.0 CHANGED
@@ -2,8 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '5.0.0'
6
- gem 'sqlite3'
5
+ gem 'rails', '~> 5.0.0'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
data/Gemfile.rails-5.1 ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.1.0'
6
+ gem 'sqlite3', '~> 1.3.6'
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'activerecord-import'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/Gemfile.rails-5.2 ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.2.0'
6
+ gem 'sqlite3', '~> 1.3.6'
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'activerecord-import'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/Gemfile.rails-6.0 ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 6.0.0'
6
+ gem 'sqlite3'
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'activerecord-import'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/Gemfile.rails-6.1 ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 6.1.0'
6
+ gem 'sqlite3'
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'activerecord-import'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/Guardfile CHANGED
@@ -1,8 +1,8 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', :version => 2, :all_after_pass => false, :all_on_start => false, :cli => "--color --format nested --fail-fast" do
4
+ guard 'rspec', version: 2, all_after_pass: false, all_on_start: false, cli: '--color --format nested --fail-fast' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
7
+ watch('spec/spec_helper.rb') { 'spec' }
8
8
  end
data/Hacking.md CHANGED
@@ -28,7 +28,7 @@ So the flow of a request goes like this:
28
28
  the notification collector
29
29
  2. The request is handled by Rails, and the installed ActiveRecord extensions
30
30
  trigger Detector callbacks
31
- 3. Detectors once called, will determine whether something noteworthy happend.
31
+ 3. Detectors once called, will determine whether something noteworthy happened.
32
32
  If yes, then a Notification is created and stored in the notification collector.
33
33
  4. Rails finishes handling the request
34
34
  5. For each notification in the collector, Bullet will iterate over each
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Bullet
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/bullet.png)](http://badge.fury.io/rb/bullet)
4
- [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.png)](http://travis-ci.org/flyerhzm/bullet)
5
- <a href="https://codeclimate.com/github/flyerhzm/bullet"><img src="https://codeclimate.com/github/flyerhzm/bullet.png" /></a>
3
+ ![Main workflow](https://github.com/flyerhzm/bullet/actions/workflows/main.yml/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/bullet.svg)](http://badge.fury.io/rb/bullet)
5
+ [![AwesomeCode Status for flyerhzm/bullet](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/repos/flyerhzm/bullet)
6
6
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
7
7
 
8
8
  The Bullet gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
@@ -13,7 +13,7 @@ Bullet gem now supports **activerecord** >= 4.0 and **mongoid** >= 4.0.
13
13
 
14
14
  If you use activerecord 2.x, please use bullet <= 4.5.0
15
15
 
16
- If you use activerecord 3.x, plesae use bullet < 5.5.0
16
+ If you use activerecord 3.x, please use bullet < 5.5.0
17
17
 
18
18
  ## External Introduction
19
19
 
@@ -34,9 +34,16 @@ or add it into a Gemfile (Bundler):
34
34
 
35
35
 
36
36
  ```ruby
37
- gem "bullet", :group => "development"
37
+ gem 'bullet', group: 'development'
38
38
  ```
39
39
 
40
+ enable the Bullet gem with generate command
41
+
42
+ ```ruby
43
+ bundle exec rails g bullet:install
44
+ ```
45
+ The generate command will auto generate the default configuration and may ask to include in the test environment as well. See below for custom configuration.
46
+
40
47
  **Note**: make sure `bullet` gem is added after activerecord (rails) and
41
48
  mongoid.
42
49
 
@@ -48,6 +55,7 @@ Bullet won't do ANYTHING unless you tell it to explicitly. Append to
48
55
  ```ruby
49
56
  config.after_initialize do
50
57
  Bullet.enable = true
58
+ Bullet.sentry = true
51
59
  Bullet.alert = true
52
60
  Bullet.bullet_logger = true
53
61
  Bullet.console = true
@@ -59,34 +67,43 @@ config.after_initialize do
59
67
  Bullet.rails_logger = true
60
68
  Bullet.honeybadger = true
61
69
  Bullet.bugsnag = true
70
+ Bullet.appsignal = true
62
71
  Bullet.airbrake = true
63
72
  Bullet.rollbar = true
64
73
  Bullet.add_footer = true
74
+ Bullet.skip_html_injection = false
65
75
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
66
- Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
76
+ Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
67
77
  Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
68
78
  end
69
79
  ```
70
80
 
71
81
  The notifier of Bullet is a wrap of [uniform_notifier](https://github.com/flyerhzm/uniform_notifier)
72
82
 
73
- The code above will enable all seven of the Bullet notification systems:
83
+ The code above will enable all of the Bullet notification systems:
74
84
  * `Bullet.enable`: enable Bullet gem, otherwise do nothing
75
85
  * `Bullet.alert`: pop up a JavaScript alert in the browser
76
86
  * `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
87
+ * `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
88
+ * `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
89
+ * `Bullet.xmpp`: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the Bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the Bullet account won't announce it's online status anymore.
77
90
  * `Bullet.rails_logger`: add warnings directly to the Rails log
78
91
  * `Bullet.honeybadger`: add notifications to Honeybadger
79
92
  * `Bullet.bugsnag`: add notifications to bugsnag
80
93
  * `Bullet.airbrake`: add notifications to airbrake
94
+ * `Bullet.appsignal`: add notifications to AppSignal
81
95
  * `Bullet.rollbar`: add notifications to rollbar
82
- * `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
83
- * `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
84
- * `Bullet.xmpp`: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the Bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the Bullet account won't announce it's online status anymore.
85
- * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
96
+ * `Bullet.sentry`: add notifications to sentry
86
97
  * `Bullet.add_footer`: adds the details in the bottom left corner of the page. Double click the footer or use close button to hide footer.
98
+ * `Bullet.skip_html_injection`: prevents Bullet from injecting code into the returned HTML. This must be false for receiving alerts, showing the footer or console logging.
99
+ * `Bullet.skip_http_headers`: don't add headers to API requests, and remove the javascript that relies on them. Note that this prevents bullet from logging warnings to the browser console or updating the footer.
87
100
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
88
101
  * `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
102
+ Each item can be a string (match substring), a regex, or an array where the first item is a path to match, and the second
103
+ item is a line number, a Range of line numbers, or a (bare) method name, to exclude only particular lines in a file.
89
104
  * `Bullet.slack`: add notifications to slack
105
+ * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
106
+
90
107
 
91
108
  Bullet also allows you to disable any of its detectors.
92
109
 
@@ -104,15 +121,15 @@ Bullet.unused_eager_loading_enable = false
104
121
  Bullet.counter_cache_enable = false
105
122
  ```
106
123
 
107
- ## Whitelist
124
+ ## Safe list
108
125
 
109
126
  Sometimes Bullet may notify you of query problems you don't care to fix, or
110
- which come from outside your code. You can whitelist these to ignore them:
127
+ which come from outside your code. You can add them to a safe list to ignore them:
111
128
 
112
129
  ```ruby
113
- Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments
114
- Bullet.add_whitelist :type => :unused_eager_loading, :class_name => "Post", :association => :comments
115
- Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities
130
+ Bullet.add_safelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments
131
+ Bullet.add_safelist :type => :unused_eager_loading, :class_name => "Post", :association => :comments
132
+ Bullet.add_safelist :type => :counter_cache, :class_name => "Country", :association => :cities
116
133
  ```
117
134
 
118
135
  If you want to skip bullet in some specific controller actions, you can
@@ -120,13 +137,14 @@ do like
120
137
 
121
138
  ```ruby
122
139
  class ApplicationController < ActionController::Base
123
- around_action :skip_bullet
140
+ around_action :skip_bullet, if: -> { defined?(Bullet) }
124
141
 
125
142
  def skip_bullet
143
+ previous_value = Bullet.enable?
126
144
  Bullet.enable = false
127
145
  yield
128
146
  ensure
129
- Bullet.enable = true
147
+ Bullet.enable = previous_value
130
148
  end
131
149
  end
132
150
  ```
@@ -175,15 +193,27 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
175
193
 
176
194
  ## Advanced
177
195
 
178
- ### Profile a job
196
+ ### Work with ActiveJob
179
197
 
180
- The Bullet gem uses rack middleware to profile requests. If you want to use Bullet without an http server, like to profile a job, you can use use profile method and fetch warnings
198
+ Include `Bullet::ActiveJob` in your `ApplicationJob`.
181
199
 
182
200
  ```ruby
183
- Bullet.profile do
184
- # do anything
201
+ class ApplicationJob < ActiveJob::Base
202
+ include Bullet::ActiveJob if Rails.env.development?
203
+ end
204
+ ```
185
205
 
186
- warnings = Bullet.warnings
206
+ ### Work with other background job solution
207
+
208
+ Use the Bullet.profile method.
209
+
210
+ ```ruby
211
+ class ApplicationJob < ActiveJob::Base
212
+ around_perform do |_job, block|
213
+ Bullet.profile do
214
+ block.call
215
+ end
216
+ end
187
217
  end
188
218
  ```
189
219
 
@@ -215,7 +245,7 @@ end
215
245
  Then wrap each test in Bullet api.
216
246
 
217
247
  ```ruby
218
- # spec/spec_helper.rb
248
+ # spec/rails_helper.rb
219
249
  if Bullet.enable?
220
250
  config.before(:each) do
221
251
  Bullet.start_request
@@ -302,19 +332,10 @@ And run
302
332
  bundle install
303
333
  ```
304
334
 
305
- 6\. enable the Bullet gem in development, add a line to
306
- `config/environments/development.rb`
335
+ 6\. enable the Bullet gem with generate command
307
336
 
308
- ```ruby
309
- config.after_initialize do
310
- Bullet.enable = true
311
- Bullet.alert = true
312
- Bullet.bullet_logger = true
313
- Bullet.console = true
314
- # Bullet.growl = true
315
- Bullet.rails_logger = true
316
- Bullet.add_footer = true
317
- end
337
+ ```
338
+ bundle exec rails g bullet:install
318
339
  ```
319
340
 
320
341
  7\. Start the server
@@ -461,4 +482,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
461
482
  Post => [:comments]
462
483
  ```
463
484
 
464
- Copyright (c) 2009 - 2016 Richard Huang (flyerhzm@gmail.com), released under the MIT license
485
+ Copyright (c) 2009 - 2019 Richard Huang (flyerhzm@gmail.com), released under the MIT license
data/Rakefile CHANGED
@@ -1,52 +1,51 @@
1
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
- require "bundler"
1
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
2
+ require 'bundler'
3
3
  Bundler.setup
4
4
 
5
- require "rake"
6
- require "rspec"
7
- require "rspec/core/rake_task"
5
+ require 'rake'
6
+ require 'rspec'
7
+ require 'rspec/core/rake_task'
8
8
 
9
- require "bullet/version"
9
+ require 'bullet/version'
10
10
 
11
11
  task :build do
12
- system "gem build bullet.gemspec"
12
+ system 'gem build bullet.gemspec'
13
13
  end
14
14
 
15
- task :install => :build do
15
+ task install: :build do
16
16
  system "sudo gem install bullet-#{Bullet::VERSION}.gem"
17
17
  end
18
18
 
19
- task :release => :build do
19
+ task release: :build do
20
20
  puts "Tagging #{Bullet::VERSION}..."
21
21
  system "git tag -a #{Bullet::VERSION} -m 'Tagging #{Bullet::VERSION}'"
22
- puts "Pushing to Github..."
23
- system "git push --tags"
24
- puts "Pushing to rubygems.org..."
22
+ puts 'Pushing to Github...'
23
+ system 'git push --tags'
24
+ puts 'Pushing to rubygems.org...'
25
25
  system "gem push bullet-#{Bullet::VERSION}.gem"
26
26
  end
27
27
 
28
28
  RSpec::Core::RakeTask.new(:spec) do |spec|
29
- spec.pattern = "spec/**/*_spec.rb"
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
30
  end
31
31
 
32
32
  RSpec::Core::RakeTask.new('spec:progress') do |spec|
33
- spec.rspec_opts = %w(--format progress)
34
- spec.pattern = "spec/**/*_spec.rb"
33
+ spec.rspec_opts = %w[--format progress]
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
35
  end
36
36
 
37
-
38
37
  begin
39
38
  require 'rdoc/task'
40
39
 
41
- desc "Generate documentation for the plugin."
40
+ desc 'Generate documentation for the plugin.'
42
41
  Rake::RDocTask.new do |rdoc|
43
- rdoc.rdoc_dir = "rdoc"
42
+ rdoc.rdoc_dir = 'rdoc'
44
43
  rdoc.title = "bullet #{Bullet::VERSION}"
45
- rdoc.rdoc_files.include("README*")
46
- rdoc.rdoc_files.include("lib/**/*.rb")
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
46
  end
48
47
  rescue LoadError
49
48
  puts 'RDocTask is not supported for this platform'
50
49
  end
51
50
 
52
- task :default => :spec
51
+ task default: :spec
data/bullet.gemspec CHANGED
@@ -1,27 +1,33 @@
1
- lib = File.expand_path('../lib/', __FILE__)
2
- $:.unshift lib unless $:.include?(lib)
1
+ # frozen_string_literal: true
3
2
 
4
- require "bullet/version"
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'bullet/version'
5
7
 
6
8
  Gem::Specification.new do |s|
7
- s.name = "bullet"
9
+ s.name = 'bullet'
8
10
  s.version = Bullet::VERSION
9
11
  s.platform = Gem::Platform::RUBY
10
- s.authors = ["Richard Huang"]
11
- s.email = ["flyerhzm@gmail.com"]
12
- s.homepage = "http://github.com/flyerhzm/bullet"
13
- s.summary = "help to kill N+1 queries and unused eager loading."
14
- s.description = "help to kill N+1 queries and unused eager loading."
12
+ s.authors = ['Richard Huang']
13
+ s.email = ['flyerhzm@gmail.com']
14
+ s.homepage = 'https://github.com/flyerhzm/bullet'
15
+ s.summary = 'help to kill N+1 queries and unused eager loading.'
16
+ s.description = 'help to kill N+1 queries and unused eager loading.'
17
+ s.metadata = {
18
+ 'changelog_uri' => 'https://github.com/flyerhzm/bullet/blob/master/CHANGELOG.md',
19
+ 'source_code_uri' => 'https://github.com/flyerhzm/bullet'
20
+ }
15
21
 
16
- s.license = 'MIT'
22
+ s.license = 'MIT'
17
23
 
18
- s.required_rubygems_version = ">= 1.3.6"
24
+ s.required_ruby_version = '>= 2.3'
25
+ s.required_rubygems_version = '>= 1.3.6'
19
26
 
20
- s.add_runtime_dependency "activesupport", ">= 3.0.0"
21
- s.add_runtime_dependency "uniform_notifier", "~> 1.10.0"
27
+ s.add_runtime_dependency 'activesupport', '>= 3.0.0'
28
+ s.add_runtime_dependency 'uniform_notifier', '~> 1.11'
22
29
 
23
30
  s.files = `git ls-files`.split("\n")
24
31
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
- s.require_paths = ["lib"]
32
+ s.require_paths = ['lib']
26
33
  end
27
-