bullet 5.7.5 → 6.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +22 -1
  3. data/CHANGELOG.md +49 -12
  4. data/Gemfile.mongoid-7.0 +15 -0
  5. data/Gemfile.rails-4.0 +1 -1
  6. data/Gemfile.rails-4.1 +1 -1
  7. data/Gemfile.rails-4.2 +1 -1
  8. data/Gemfile.rails-5.0 +1 -1
  9. data/Gemfile.rails-5.1 +1 -1
  10. data/Gemfile.rails-5.2 +2 -2
  11. data/Gemfile.rails-6.0 +15 -0
  12. data/Gemfile.rails-6.1 +15 -0
  13. data/README.md +38 -13
  14. data/Rakefile +1 -1
  15. data/bullet.gemspec +8 -3
  16. data/lib/bullet.rb +50 -22
  17. data/lib/bullet/active_job.rb +13 -0
  18. data/lib/bullet/active_record4.rb +12 -35
  19. data/lib/bullet/active_record41.rb +10 -30
  20. data/lib/bullet/active_record42.rb +12 -27
  21. data/lib/bullet/active_record5.rb +197 -177
  22. data/lib/bullet/active_record52.rb +191 -166
  23. data/lib/bullet/active_record60.rb +278 -0
  24. data/lib/bullet/active_record61.rb +278 -0
  25. data/lib/bullet/bullet_xhr.js +63 -0
  26. data/lib/bullet/dependency.rb +54 -34
  27. data/lib/bullet/detector/association.rb +26 -20
  28. data/lib/bullet/detector/base.rb +1 -2
  29. data/lib/bullet/detector/counter_cache.rb +14 -9
  30. data/lib/bullet/detector/n_plus_one_query.rb +27 -17
  31. data/lib/bullet/detector/unused_eager_loading.rb +7 -3
  32. data/lib/bullet/ext/object.rb +5 -3
  33. data/lib/bullet/ext/string.rb +1 -1
  34. data/lib/bullet/mongoid4x.rb +4 -7
  35. data/lib/bullet/mongoid5x.rb +4 -7
  36. data/lib/bullet/mongoid6x.rb +8 -11
  37. data/lib/bullet/mongoid7x.rb +57 -0
  38. data/lib/bullet/notification/base.rb +15 -19
  39. data/lib/bullet/notification/n_plus_one_query.rb +2 -4
  40. data/lib/bullet/notification/unused_eager_loading.rb +2 -4
  41. data/lib/bullet/rack.rb +54 -28
  42. data/lib/bullet/stack_trace_filter.rb +39 -30
  43. data/lib/bullet/version.rb +1 -1
  44. data/lib/generators/bullet/install_generator.rb +26 -26
  45. data/perf/benchmark.rb +8 -14
  46. data/spec/bullet/detector/counter_cache_spec.rb +6 -6
  47. data/spec/bullet/detector/n_plus_one_query_spec.rb +30 -3
  48. data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -6
  49. data/spec/bullet/ext/object_spec.rb +9 -4
  50. data/spec/bullet/notification/base_spec.rb +1 -3
  51. data/spec/bullet/notification/n_plus_one_query_spec.rb +16 -3
  52. data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
  53. data/spec/bullet/rack_spec.rb +140 -5
  54. data/spec/bullet/registry/association_spec.rb +2 -2
  55. data/spec/bullet/registry/base_spec.rb +1 -1
  56. data/spec/bullet_spec.rb +10 -29
  57. data/spec/integration/active_record/association_spec.rb +122 -118
  58. data/spec/integration/counter_cache_spec.rb +11 -31
  59. data/spec/integration/mongoid/association_spec.rb +18 -32
  60. data/spec/models/attachment.rb +5 -0
  61. data/spec/models/client.rb +2 -0
  62. data/spec/models/firm.rb +1 -0
  63. data/spec/models/folder.rb +1 -2
  64. data/spec/models/group.rb +3 -0
  65. data/spec/models/page.rb +1 -2
  66. data/spec/models/post.rb +15 -0
  67. data/spec/models/submission.rb +1 -0
  68. data/spec/models/user.rb +1 -0
  69. data/spec/models/writer.rb +1 -2
  70. data/spec/spec_helper.rb +6 -10
  71. data/spec/support/bullet_ext.rb +8 -9
  72. data/spec/support/mongo_seed.rb +2 -16
  73. data/spec/support/sqlite_seed.rb +17 -2
  74. data/test.sh +2 -0
  75. data/update.sh +1 -0
  76. metadata +24 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fb27c10f2796dc6cc38899be2b88943f6c124d80
4
- data.tar.gz: c89d95e08212b3bf8da49f2ce4c542ec2aa3021d
2
+ SHA256:
3
+ metadata.gz: 74ea4e863bfe254dde17af73253ffe7041cd2b2dabee2dad05d1eccb6904f229
4
+ data.tar.gz: 284dcd1a516922384bdaf1b3dd9e6a5e6776c213c3ecbc9ca41b223c5b92d36b
5
5
  SHA512:
6
- metadata.gz: 8f4d67bebf52a6730fa623bb150717e56c052605fc339f37d89d915af0981e442200e2bfee5c3405e6269d0907dc4e4f89fd2965000e637555aa8614580837c0
7
- data.tar.gz: 3fbfc65e37e50444107e153050b33f66fe51037fd9d325438015d51c71f4a5ccb387e9b76ba28a2c753c9f9227653686535c857f457c80d62213cdda070b9c18
6
+ metadata.gz: 26c43bfdac9582f059d067d4f56d4d85ed28416654ff5fd4686bf9977cbfbc8d92f887079954662e904fbe3d1b861d02482ac2fefac30a859fbdad8c3833e225
7
+ data.tar.gz: 48decfa9d28b9936f5c1f39c669b6e8061fae649f9036c29d4b28138083a43db8739f3b73bb9c390e9f6baea62aa1f66f79e8ced69cf13e789b8f116c101f25f
data/.travis.yml CHANGED
@@ -1,12 +1,33 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.0
4
+ - 2.6.0
5
5
  gemfile:
6
+ - Gemfile.rails-6.0
7
+ - Gemfile.rails-5.2
6
8
  - Gemfile.rails-5.1
7
9
  - Gemfile.rails-5.0
8
10
  - Gemfile.rails-4.2
9
11
  - Gemfile.rails-4.1
10
12
  - Gemfile.rails-4.0
13
+ matrix:
14
+ exclude:
15
+ - rvm: 2.3.0
16
+ gemfile: Gemfile.rails-6.0
17
+ - rvm: 2.6.0
18
+ gemfile: Gemfile.rails-5.2
19
+ - rvm: 2.6.0
20
+ gemfile: Gemfile.rails-5.1
21
+ - rvm: 2.6.0
22
+ gemfile: Gemfile.rails-5.0
23
+ - rvm: 2.6.0
24
+ gemfile: Gemfile.rails-4.2
25
+ - rvm: 2.6.0
26
+ gemfile: Gemfile.rails-4.1
27
+ - rvm: 2.6.0
28
+ gemfile: Gemfile.rails-4.0
11
29
  env:
12
30
  - DB=sqlite
31
+ before_install:
32
+ - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
33
+ - gem install bundler -v '< 2'
data/CHANGELOG.md CHANGED
@@ -1,27 +1,64 @@
1
1
  ## Next Release
2
2
 
3
- ## 5.7.5 (12/03/2018)
3
+ ## 6.1.4 (02/26/2021)
4
4
 
5
- * Fix duplicate logs in mongoid 4.x and 5.x version
6
- * Add magic comment frozen_string_literal: true
5
+ * Added an option to stop adding HTTP headers to API requests
7
6
 
8
- ## 5.7.4 (10/03/2018)
7
+ ## 6.1.3 (01/21/2021)
9
8
 
10
- * Avoid Bullet from making extra queries in mongoid6
11
- * Use caller for ruby 1.9 while caller_locations for 2.0+
9
+ * Consider ThroughAssociation at SingularAssociation like CollectionAssociation
10
+ * Add xhr_script only when add_footer is enabled
12
11
 
13
- ## 5.7.3 (17/02/2018)
12
+ ## 6.1.2 (12/12/2020)
14
13
 
15
- * Exclude configured bundler path in addition to '/vendor'
16
- * Support rails 5.1.5
14
+ * Revert "Make whitelist thread safe"
17
15
 
18
- ## 5.7.2 (18/01/2018)
16
+ ## 6.1.1 (12/12/2020)
19
17
 
20
- * Fix `caller_path` in `excluded_stacktrace_path`
18
+ * Add support Rails 6.1
19
+ * Make whitelist thread safe
20
+
21
+ ## 6.1.0 (12/28/2019)
22
+
23
+ * Add skip_html_injection flag
24
+ * Remove writer hack in active_record6
25
+ * Use modern includes syntax in warnings
26
+ * Fix warning: The last argument is used as the keyword parameter
27
+
28
+ ## 6.0.2 (08/20/2019)
29
+
30
+ * Fully support Rails 6.0
31
+
32
+ ## 6.0.1 (06/26/2019)
21
33
 
22
- ## 5.7.1 (07/01/2017)
34
+ * Add Bullet::ActiveJob
35
+ * Prevent "Maximum call stack exceeded" errors when used with Turbolinks
23
36
 
37
+ ## 6.0.0 (04/25/2019)
38
+
39
+ * Add XHR support to Bullet
40
+ * Support Rails 6.0
41
+ * Handle case where ID is manually set on unpersisted record
42
+
43
+ ## 5.9.0 (11/11/2018)
44
+
45
+ * Require Ruby 2.3+
46
+ * Support Mongo 7.x
47
+
48
+ ## 5.8.0 (10/29/2018)
49
+
50
+ * Fix through reflection for rails 5.x
51
+ * Fix false positive in after_save/after_create callbacks
52
+ * Don't triger a preload error on "manual" preloads
53
+ * Avoid Bullet from making extra queries in mongoid6
54
+ * Support option for #first and #last on mongoid6.x
55
+ * Fix duplicate logs in mongoid 4.x and 5.x version
56
+ * Use caller for ruby 1.9 while caller_locations for 2.0+
57
+ * Extend stacktrace matching for sub-file precision
58
+ * Exclude configured bundler path in addition to '/vendor'
59
+ * Fix `caller_path` in `excluded_stacktrace_path`
24
60
  * Update `uniform_notifier` dependency to add Sentry support
61
+ * Integrate awesomecode.io and refactor code
25
62
 
26
63
  ## 5.7.0 (12/03/2017)
27
64
 
@@ -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
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.0.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
 
data/Gemfile.rails-5.1 CHANGED
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.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
 
data/Gemfile.rails-5.2 CHANGED
@@ -2,8 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 5.2.0.beta2'
6
- gem 'sqlite3'
5
+ gem 'rails', '~> 5.2.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-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/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
- [![AwesomeCode Status](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/projects/2)
3
+ [![Gem Version](https://badge.fury.io/rb/bullet.svg)](http://badge.fury.io/rb/bullet)
4
+ [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.svg)](http://travis-ci.org/flyerhzm/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.
@@ -37,6 +37,13 @@ or add it into a Gemfile (Bundler):
37
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
 
@@ -63,8 +70,9 @@ config.after_initialize do
63
70
  Bullet.airbrake = true
64
71
  Bullet.rollbar = true
65
72
  Bullet.add_footer = true
73
+ Bullet.skip_html_injection = false
66
74
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
67
- Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
75
+ Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
68
76
  Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
69
77
  end
70
78
  ```
@@ -85,8 +93,12 @@ The code above will enable all of the Bullet notification systems:
85
93
  * `Bullet.rollbar`: add notifications to rollbar
86
94
  * `Bullet.sentry`: add notifications to sentry
87
95
  * `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.
96
+ * `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.
97
+ * `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.
88
98
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
89
99
  * `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
100
+ 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
101
+ item is a line number, a Range of line numbers, or a (bare) method name, to exclude only particular lines in a file.
90
102
  * `Bullet.slack`: add notifications to slack
91
103
  * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
92
104
 
@@ -123,13 +135,14 @@ do like
123
135
 
124
136
  ```ruby
125
137
  class ApplicationController < ActionController::Base
126
- around_action :skip_bullet
138
+ around_action :skip_bullet, if: -> { defined?(Bullet) }
127
139
 
128
140
  def skip_bullet
141
+ previous_value = Bullet.enable?
129
142
  Bullet.enable = false
130
143
  yield
131
144
  ensure
132
- Bullet.enable = true
145
+ Bullet.enable = previous_value
133
146
  end
134
147
  end
135
148
  ```
@@ -178,15 +191,27 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
178
191
 
179
192
  ## Advanced
180
193
 
181
- ### Profile a job
194
+ ### Work with ActiveJob
182
195
 
183
- 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
196
+ Include `Bullet::ActiveJob` in your `ApplicationJob`.
184
197
 
185
198
  ```ruby
186
- Bullet.profile do
187
- # do anything
199
+ class ApplicationJob < ActiveJob::Base
200
+ include Bullet::ActiveJob if Rails.env.development?
201
+ end
202
+ ```
203
+
204
+ ### Work with other background job solution
205
+
206
+ Use the Bullet.profile method.
188
207
 
189
- warnings = Bullet.warnings
208
+ ```ruby
209
+ class ApplicationJob < ActiveJob::Base
210
+ around_perform do |_job, block|
211
+ Bullet.profile do
212
+ block.call
213
+ end
214
+ end
190
215
  end
191
216
  ```
192
217
 
@@ -218,7 +243,7 @@ end
218
243
  Then wrap each test in Bullet api.
219
244
 
220
245
  ```ruby
221
- # spec/spec_helper.rb
246
+ # spec/rails_helper.rb
222
247
  if Bullet.enable?
223
248
  config.before(:each) do
224
249
  Bullet.start_request
@@ -455,4 +480,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
455
480
  Post => [:comments]
456
481
  ```
457
482
 
458
- Copyright (c) 2009 - 2016 Richard Huang (flyerhzm@gmail.com), released under the MIT license
483
+ Copyright (c) 2009 - 2019 Richard Huang (flyerhzm@gmail.com), released under the MIT license
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
2
2
  require 'bundler'
3
3
  Bundler.setup
4
4
 
data/bullet.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib/', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  require 'bullet/version'
@@ -14,13 +14,18 @@ Gem::Specification.new do |s|
14
14
  s.homepage = 'https://github.com/flyerhzm/bullet'
15
15
  s.summary = 'help to kill N+1 queries and unused eager loading.'
16
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
+ }
17
21
 
18
- s.license = 'MIT'
22
+ s.license = 'MIT'
19
23
 
24
+ s.required_ruby_version = '>= 2.3'
20
25
  s.required_rubygems_version = '>= 1.3.6'
21
26
 
22
27
  s.add_runtime_dependency 'activesupport', '>= 3.0.0'
23
- s.add_runtime_dependency 'uniform_notifier', '~> 1.11.0'
28
+ s.add_runtime_dependency 'uniform_notifier', '~> 1.11'
24
29
 
25
30
  s.files = `git ls-files`.split("\n")
26
31
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/bullet.rb CHANGED
@@ -14,15 +14,16 @@ module Bullet
14
14
  autoload :ActiveRecord, "bullet/#{active_record_version}" if active_record?
15
15
  autoload :Mongoid, "bullet/#{mongoid_version}" if mongoid?
16
16
  autoload :Rack, 'bullet/rack'
17
+ autoload :ActiveJob, 'bullet/active_job'
17
18
  autoload :Notification, 'bullet/notification'
18
19
  autoload :Detector, 'bullet/detector'
19
20
  autoload :Registry, 'bullet/registry'
20
21
  autoload :NotificationCollector, 'bullet/notification_collector'
21
22
 
22
- BULLET_DEBUG = 'BULLET_DEBUG'.freeze
23
- TRUE = 'true'.freeze
23
+ BULLET_DEBUG = 'BULLET_DEBUG'
24
+ TRUE = 'true'
24
25
 
25
- if defined? Rails::Railtie
26
+ if defined?(Rails::Railtie)
26
27
  class BulletRailtie < Rails::Railtie
27
28
  initializer 'bullet.configure_rails_initialization' do |app|
28
29
  app.middleware.use Bullet::Rack
@@ -31,28 +32,36 @@ module Bullet
31
32
  end
32
33
 
33
34
  class << self
34
- attr_writer :n_plus_one_query_enable, :unused_eager_loading_enable, :counter_cache_enable, :stacktrace_includes, :stacktrace_excludes
35
+ attr_writer :n_plus_one_query_enable,
36
+ :unused_eager_loading_enable,
37
+ :counter_cache_enable,
38
+ :stacktrace_includes,
39
+ :stacktrace_excludes,
40
+ :skip_html_injection
35
41
  attr_reader :whitelist
36
- attr_accessor :add_footer, :orm_pathches_applied
42
+ attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers
37
43
 
38
- available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
39
- available_notifiers << { to: UniformNotifier }
40
- delegate(*available_notifiers)
44
+ available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
45
+ available_notifiers_options = { to: UniformNotifier }
46
+ delegate(*available_notifiers, **available_notifiers_options)
41
47
 
42
48
  def raise=(should_raise)
43
49
  UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
44
50
  end
45
51
 
46
- DETECTORS = [Bullet::Detector::NPlusOneQuery,
47
- Bullet::Detector::UnusedEagerLoading,
48
- Bullet::Detector::CounterCache].freeze
52
+ DETECTORS = [
53
+ Bullet::Detector::NPlusOneQuery,
54
+ Bullet::Detector::UnusedEagerLoading,
55
+ Bullet::Detector::CounterCache
56
+ ].freeze
49
57
 
50
58
  def enable=(enable)
51
59
  @enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
60
+
52
61
  if enable?
53
62
  reset_whitelist
54
- unless orm_pathches_applied
55
- self.orm_pathches_applied = true
63
+ unless orm_patches_applied
64
+ self.orm_patches_applied = true
56
65
  Bullet::Mongoid.enable if mongoid?
57
66
  Bullet::ActiveRecord.enable if active_record?
58
67
  end
@@ -63,6 +72,10 @@ module Bullet
63
72
  !!@enable
64
73
  end
65
74
 
75
+ def app_root
76
+ @app_root ||= (defined?(::Rails.root) ? Rails.root.to_s : Dir.pwd).to_s
77
+ end
78
+
66
79
  def n_plus_one_query_enable?
67
80
  enable? && !!@n_plus_one_query_enable
68
81
  end
@@ -76,11 +89,11 @@ module Bullet
76
89
  end
77
90
 
78
91
  def stacktrace_includes
79
- @stacktrace_includes || []
92
+ @stacktrace_includes ||= []
80
93
  end
81
94
 
82
95
  def stacktrace_excludes
83
- @stacktrace_excludes || []
96
+ @stacktrace_excludes ||= []
84
97
  end
85
98
 
86
99
  def add_whitelist(options)
@@ -111,9 +124,8 @@ module Bullet
111
124
  def bullet_logger=(active)
112
125
  if active
113
126
  require 'fileutils'
114
- root_path = (rails? ? Rails.root.to_s : Dir.pwd).to_s
115
- FileUtils.mkdir_p(root_path + '/log')
116
- bullet_log_file = File.open("#{root_path}/log/bullet.log", 'a+')
127
+ FileUtils.mkdir_p(app_root + '/log')
128
+ bullet_log_file = File.open("#{app_root}/log/bullet.log", 'a+')
117
129
  bullet_log_file.sync = true
118
130
  UniformNotifier.customized_logger = bullet_log_file
119
131
  end
@@ -163,15 +175,14 @@ module Bullet
163
175
 
164
176
  def notification?
165
177
  return unless start?
178
+
166
179
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
167
180
  notification_collector.notifications_present?
168
181
  end
169
182
 
170
183
  def gather_inline_notifications
171
184
  responses = []
172
- for_each_active_notifier_with_notification do |notification|
173
- responses << notification.notify_inline
174
- end
185
+ for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
175
186
  responses.join("\n")
176
187
  end
177
188
 
@@ -184,9 +195,15 @@ module Bullet
184
195
  end
185
196
 
186
197
  def footer_info
198
+ info = []
199
+ notification_collector.collection.each { |notification| info << notification.short_notice }
200
+ info
201
+ end
202
+
203
+ def text_notifications
187
204
  info = []
188
205
  notification_collector.collection.each do |notification|
189
- info << notification.short_notice
206
+ info << notification.notification_data.values.compact.join("\n")
190
207
  end
191
208
  info
192
209
  end
@@ -201,6 +218,7 @@ module Bullet
201
218
 
202
219
  def profile
203
220
  return_value = nil
221
+
204
222
  if Bullet.enable?
205
223
  begin
206
224
  Bullet.start_request
@@ -218,6 +236,16 @@ module Bullet
218
236
  return_value
219
237
  end
220
238
 
239
+ def console_enabled?
240
+ UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
241
+ end
242
+
243
+ def inject_into_page?
244
+ return false if defined?(@skip_html_injection) && @skip_html_injection
245
+
246
+ console_enabled? || add_footer
247
+ end
248
+
221
249
  private
222
250
 
223
251
  def for_each_active_notifier_with_notification