bullet 6.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +20 -1
  3. data/CHANGELOG.md +17 -1
  4. data/Gemfile.rails-6.0 +1 -1
  5. data/README.md +23 -9
  6. data/lib/bullet.rb +26 -16
  7. data/lib/bullet/active_job.rb +9 -0
  8. data/lib/bullet/active_record4.rb +9 -24
  9. data/lib/bullet/active_record41.rb +7 -19
  10. data/lib/bullet/active_record42.rb +8 -16
  11. data/lib/bullet/active_record5.rb +188 -170
  12. data/lib/bullet/active_record52.rb +176 -161
  13. data/lib/bullet/active_record60.rb +193 -171
  14. data/lib/bullet/bullet_xhr.js +20 -15
  15. data/lib/bullet/dependency.rb +36 -34
  16. data/lib/bullet/detector/association.rb +24 -18
  17. data/lib/bullet/detector/base.rb +1 -2
  18. data/lib/bullet/detector/counter_cache.rb +10 -6
  19. data/lib/bullet/detector/n_plus_one_query.rb +18 -8
  20. data/lib/bullet/detector/unused_eager_loading.rb +5 -2
  21. data/lib/bullet/mongoid4x.rb +2 -6
  22. data/lib/bullet/mongoid5x.rb +2 -6
  23. data/lib/bullet/mongoid6x.rb +2 -6
  24. data/lib/bullet/mongoid7x.rb +2 -6
  25. data/lib/bullet/notification/base.rb +14 -18
  26. data/lib/bullet/notification/n_plus_one_query.rb +2 -4
  27. data/lib/bullet/notification/unused_eager_loading.rb +2 -4
  28. data/lib/bullet/rack.rb +5 -3
  29. data/lib/bullet/stack_trace_filter.rb +5 -10
  30. data/lib/bullet/version.rb +1 -1
  31. data/lib/generators/bullet/install_generator.rb +4 -2
  32. data/perf/benchmark.rb +8 -14
  33. data/spec/bullet/detector/counter_cache_spec.rb +5 -5
  34. data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
  35. data/spec/bullet/detector/unused_eager_loading_spec.rb +29 -12
  36. data/spec/bullet/notification/base_spec.rb +1 -3
  37. data/spec/bullet/notification/n_plus_one_query_spec.rb +18 -3
  38. data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
  39. data/spec/bullet/rack_spec.rb +20 -5
  40. data/spec/bullet/registry/association_spec.rb +2 -2
  41. data/spec/bullet/registry/base_spec.rb +1 -1
  42. data/spec/bullet_spec.rb +10 -29
  43. data/spec/integration/active_record/association_spec.rb +42 -122
  44. data/spec/integration/counter_cache_spec.rb +10 -30
  45. data/spec/integration/mongoid/association_spec.rb +18 -32
  46. data/spec/models/folder.rb +1 -2
  47. data/spec/models/group.rb +1 -2
  48. data/spec/models/page.rb +1 -2
  49. data/spec/models/writer.rb +1 -2
  50. data/spec/spec_helper.rb +6 -10
  51. data/spec/support/bullet_ext.rb +8 -9
  52. data/spec/support/mongo_seed.rb +2 -16
  53. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 749d1d92dc0373b1f2521c85825dfea656e985c438cdfafe774242b31f25c2d5
4
- data.tar.gz: 4e76a9da65613f2b9cf3802f4969f84c1e5bb9849c5892898fa9d999fde3900c
3
+ metadata.gz: dd668fdfd675ea8437eee0242974d7cb1cfacc0479be4cc5f3f58ee7d05a6d63
4
+ data.tar.gz: 3d841fb8471fe18b66135fa087ee3d1874f412c114d09ba05ba150e2daaf9775
5
5
  SHA512:
6
- metadata.gz: 72f8f18edecb79d8631a215229afb71bb94050c0fcc65794a88dc3adf21545acf4ae38eb59bd6bdfa0e34609854ab149d02f47e761fba00452e28f2575306376
7
- data.tar.gz: 94058fcb502d63ce470b6dfa06d05dd367c8a7e251948040b91c22164d6583d8a82ab120bb2a42d109c121170042573c9964aaa55ebc0093c07adc1fb8f23fd5
6
+ metadata.gz: 714c614f2cf44f332f4f9996638c10dca565c92a2279316509256fefba2ca824fc9c71d2a3c3e4ca28edfc45849f76b61e521158e0051c365f5b8a81f41e9d8d
7
+ data.tar.gz: a3b1a7e58b6e5554a641aa4b8edf16dbb4983b2f7a072c5b7275ee04a7251e4d095fed37f82d2945ef759603c8aeaf8a394d9e7fcf9f70a723e6235ab5f3e646
@@ -1,7 +1,7 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.0
4
+ - 2.6.0
5
5
  gemfile:
6
6
  - Gemfile.rails-6.0
7
7
  - Gemfile.rails-5.2
@@ -10,5 +10,24 @@ gemfile:
10
10
  - Gemfile.rails-4.2
11
11
  - Gemfile.rails-4.1
12
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
13
29
  env:
14
30
  - DB=sqlite
31
+ before_install:
32
+ - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
33
+ - gem install bundler -v '< 2'
@@ -1,6 +1,22 @@
1
1
  ## Next Release
2
2
 
3
- ## 6.0.0 (02/22/2019)
3
+ ## 6.1.0 (12/28/2019)
4
+
5
+ * Add skip_html_injection flag
6
+ * Remove writer hack in active_record6
7
+ * Use modern includes syntax in warnings
8
+ * Fix warning: The last argument is used as the keyword parameter
9
+
10
+ ## 6.0.2 (08/20/2019)
11
+
12
+ * Fully support Rails 6.0
13
+
14
+ ## 6.0.1 (06/26/2019)
15
+
16
+ * Add Bullet::ActiveJob
17
+ * Prevent "Maximum call stack exceeded" errors when used with Turbolinks
18
+
19
+ ## 6.0.0 (04/25/2019)
4
20
 
5
21
  * Add XHR support to Bullet
6
22
  * Support Rails 6.0
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '6.0.0.rc1'
5
+ gem 'rails', '6.0.0'
6
6
  gem 'sqlite3'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
data/README.md CHANGED
@@ -1,7 +1,7 @@
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)
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
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
 
@@ -63,6 +63,7 @@ config.after_initialize do
63
63
  Bullet.airbrake = true
64
64
  Bullet.rollbar = true
65
65
  Bullet.add_footer = true
66
+ Bullet.skip_html_injection = false
66
67
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
67
68
  Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
68
69
  Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
@@ -85,6 +86,7 @@ The code above will enable all of the Bullet notification systems:
85
86
  * `Bullet.rollbar`: add notifications to rollbar
86
87
  * `Bullet.sentry`: add notifications to sentry
87
88
  * `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.
89
+ * `Bullet.skip_html_injection`: prevents Bullet from injecting XHR into the returned HTML. This must be false for receiving alerts or console logging.
88
90
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
89
91
  * `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
90
92
  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
@@ -125,7 +127,7 @@ do like
125
127
 
126
128
  ```ruby
127
129
  class ApplicationController < ActionController::Base
128
- around_action :skip_bullet
130
+ around_action :skip_bullet, if: -> { defined?(Bullet) }
129
131
 
130
132
  def skip_bullet
131
133
  previous_value = Bullet.enable?
@@ -181,15 +183,27 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
181
183
 
182
184
  ## Advanced
183
185
 
184
- ### Profile a job
186
+ ### Work with ActiveJob
185
187
 
186
- 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 the profile method and fetch warnings
188
+ Include `Bullet::ActiveJob` in your `ApplicationJob`.
187
189
 
188
190
  ```ruby
189
- Bullet.profile do
190
- # do anything
191
+ class ApplicationJob < ActiveJob::Base
192
+ include Bullet::ActiveJob if Rails.env.development?
193
+ end
194
+ ```
195
+
196
+ ### Work with other background job solution
191
197
 
192
- warnings = Bullet.warnings
198
+ Use the Bullet.profile method.
199
+
200
+ ```ruby
201
+ class ApplicationJob < ActiveJob::Base
202
+ around_perform do |_job, block|
203
+ Bullet.profile do
204
+ block.call
205
+ end
206
+ end
193
207
  end
194
208
  ```
195
209
 
@@ -458,4 +472,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
458
472
  Post => [:comments]
459
473
  ```
460
474
 
461
- Copyright (c) 2009 - 2016 Richard Huang (flyerhzm@gmail.com), released under the MIT license
475
+ Copyright (c) 2009 - 2019 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -14,6 +14,7 @@ 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'
@@ -22,7 +23,7 @@ module Bullet
22
23
  BULLET_DEBUG = 'BULLET_DEBUG'
23
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
37
43
 
38
44
  available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
39
- available_notifiers << { to: UniformNotifier }
40
- delegate(*available_notifiers)
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
@@ -173,9 +182,7 @@ module Bullet
173
182
 
174
183
  def gather_inline_notifications
175
184
  responses = []
176
- for_each_active_notifier_with_notification do |notification|
177
- responses << notification.notify_inline
178
- end
185
+ for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
179
186
  responses.join("\n")
180
187
  end
181
188
 
@@ -189,9 +196,7 @@ module Bullet
189
196
 
190
197
  def footer_info
191
198
  info = []
192
- notification_collector.collection.each do |notification|
193
- info << notification.short_notice
194
- end
199
+ notification_collector.collection.each { |notification| info << notification.short_notice }
195
200
  info
196
201
  end
197
202
 
@@ -213,6 +218,7 @@ module Bullet
213
218
 
214
219
  def profile
215
220
  return_value = nil
221
+
216
222
  if Bullet.enable?
217
223
  begin
218
224
  Bullet.start_request
@@ -234,6 +240,10 @@ module Bullet
234
240
  UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
235
241
  end
236
242
 
243
+ def skip_html_injection?
244
+ @skip_html_injection || false
245
+ end
246
+
237
247
  private
238
248
 
239
249
  def for_each_active_notifier_with_notification
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bullet
4
+ module ActiveJob
5
+ def self.included(base)
6
+ base.class_eval { around_perform { |_job, block| Bullet.profile { block.call } } }
7
+ end
8
+ end
9
+ end
@@ -5,7 +5,7 @@ module Bullet
5
5
  def self.enable
6
6
  require 'active_record'
7
7
  ::ActiveRecord::Base.class_eval do
8
- class <<self
8
+ class << self
9
9
  alias_method :origin_find_by_sql, :find_by_sql
10
10
  def find_by_sql(sql, binds = [])
11
11
  result = origin_find_by_sql(sql, binds)
@@ -49,9 +49,7 @@ module Bullet
49
49
 
50
50
  ::ActiveRecord::Persistence.class_eval do
51
51
  def _create_record_with_bullet(*args)
52
- _create_record_without_bullet(*args).tap do
53
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
54
- end
52
+ _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
55
53
  end
56
54
  alias_method_chain :_create_record, :bullet
57
55
  end
@@ -62,13 +60,12 @@ module Bullet
62
60
  alias_method :origin_initialize, :initialize
63
61
  def initialize(records, associations, preload_scope = nil)
64
62
  origin_initialize(records, associations, preload_scope)
63
+
65
64
  if Bullet.start?
66
65
  records = [records].flatten.compact.uniq
67
66
  return if records.empty?
68
67
 
69
- records.each do |record|
70
- Bullet::Detector::Association.add_object_associations(record, associations)
71
- end
68
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
72
69
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
73
70
  end
74
71
  end
@@ -81,9 +78,7 @@ module Bullet
81
78
  records = origin_find_with_associations
82
79
  if Bullet.start?
83
80
  associations = (eager_load_values + includes_values).uniq
84
- records.each do |record|
85
- Bullet::Detector::Association.add_object_associations(record, associations)
86
- end
81
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
87
82
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
88
83
  end
89
84
  records
@@ -128,17 +123,13 @@ module Bullet
128
123
  # call one to many associations
129
124
  alias_method :origin_load_target, :load_target
130
125
  def load_target
131
- if Bullet.start?
132
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
133
- end
126
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
134
127
  origin_load_target
135
128
  end
136
129
 
137
130
  alias_method :origin_include?, :include?
138
131
  def include?(object)
139
- if Bullet.start?
140
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
141
- end
132
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
142
133
  origin_include?(object)
143
134
  end
144
135
  end
@@ -156,9 +147,7 @@ module Bullet
156
147
  ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
157
148
  alias_method :origin_empty?, :empty?
158
149
  def empty?
159
- if Bullet.start? && !loaded?
160
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
161
- end
150
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !loaded?
162
151
  origin_empty?
163
152
  end
164
153
  end
@@ -181,15 +170,11 @@ module Bullet
181
170
  ::ActiveRecord::Associations::HasManyAssociation.class_eval do
182
171
  alias_method :origin_has_cached_counter?, :has_cached_counter?
183
172
 
184
- # rubocop:disable Style/MethodCallWithoutArgsParentheses
185
173
  def has_cached_counter?(reflection = reflection())
186
174
  result = origin_has_cached_counter?(reflection)
187
- if Bullet.start? && !result
188
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
189
- end
175
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) if Bullet.start? && !result
190
176
  result
191
177
  end
192
- # rubocop:enable Style/MethodCallWithoutArgsParentheses
193
178
  end
194
179
  end
195
180
  end
@@ -5,7 +5,7 @@ module Bullet
5
5
  def self.enable
6
6
  require 'active_record'
7
7
  ::ActiveRecord::Base.class_eval do
8
- class <<self
8
+ class << self
9
9
  alias_method :origin_find_by_sql, :find_by_sql
10
10
  def find_by_sql(sql, binds = [])
11
11
  result = origin_find_by_sql(sql, binds)
@@ -51,9 +51,7 @@ module Bullet
51
51
 
52
52
  ::ActiveRecord::Persistence.class_eval do
53
53
  def _create_record_with_bullet(*args)
54
- _create_record_without_bullet(*args).tap do
55
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
56
- end
54
+ _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
57
55
  end
58
56
  alias_method_chain :_create_record, :bullet
59
57
  end
@@ -65,9 +63,7 @@ module Bullet
65
63
  if Bullet.start?
66
64
  records.compact!
67
65
  if records.first.class.name !~ /^HABTM_/
68
- records.each do |record|
69
- Bullet::Detector::Association.add_object_associations(record, association)
70
- end
66
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
71
67
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
72
68
  end
73
69
  end
@@ -84,9 +80,7 @@ module Bullet
84
80
  records = origin_find_with_associations
85
81
  if Bullet.start?
86
82
  associations = (eager_load_values + includes_values).uniq
87
- records.each do |record|
88
- Bullet::Detector::Association.add_object_associations(record, associations)
89
- end
83
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
90
84
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
91
85
  end
92
86
  records
@@ -131,9 +125,7 @@ module Bullet
131
125
  # call one to many associations
132
126
  alias_method :origin_load_target, :load_target
133
127
  def load_target
134
- if Bullet.start?
135
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
136
- end
128
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !@inversed
137
129
  origin_load_target
138
130
  end
139
131
 
@@ -147,9 +139,7 @@ module Bullet
147
139
 
148
140
  alias_method :origin_include?, :include?
149
141
  def include?(object)
150
- if Bullet.start?
151
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
152
- end
142
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
153
143
  origin_include?(object)
154
144
  end
155
145
  end
@@ -173,9 +163,7 @@ module Bullet
173
163
  alias_method :origin_count_records, :count_records
174
164
  def count_records
175
165
  result = has_cached_counter?
176
- if Bullet.start? && !result
177
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
178
- end
166
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
179
167
  origin_count_records
180
168
  end
181
169
  end
@@ -5,7 +5,7 @@ module Bullet
5
5
  def self.enable
6
6
  require 'active_record'
7
7
  ::ActiveRecord::Base.class_eval do
8
- class <<self
8
+ class << self
9
9
  alias_method :origin_find, :find
10
10
  def find(*args)
11
11
  result = origin_find(*args)
@@ -45,9 +45,7 @@ module Bullet
45
45
 
46
46
  ::ActiveRecord::Persistence.class_eval do
47
47
  def _create_record_with_bullet(*args)
48
- _create_record_without_bullet(*args).tap do
49
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
50
- end
48
+ _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
51
49
  end
52
50
  alias_method_chain :_create_record, :bullet
53
51
  end
@@ -80,9 +78,7 @@ module Bullet
80
78
  if Bullet.start?
81
79
  records.compact!
82
80
  if records.first.class.name !~ /^HABTM_/
83
- records.each do |record|
84
- Bullet::Detector::Association.add_object_associations(record, association)
85
- end
81
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
86
82
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
87
83
  end
88
84
  end
@@ -99,9 +95,7 @@ module Bullet
99
95
  records = origin_find_with_associations
100
96
  if Bullet.start?
101
97
  associations = (eager_load_values + includes_values).uniq
102
- records.each do |record|
103
- Bullet::Detector::Association.add_object_associations(record, associations)
104
- end
98
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
105
99
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
106
100
  end
107
101
  records
@@ -195,9 +189,7 @@ module Bullet
195
189
 
196
190
  alias_method :origin_include?, :include?
197
191
  def include?(object)
198
- if Bullet.start?
199
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
200
- end
192
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
201
193
  origin_include?(object)
202
194
  end
203
195
  end
@@ -207,9 +199,11 @@ module Bullet
207
199
  alias_method :origin_reader, :reader
208
200
  def reader(force_reload = false)
209
201
  result = origin_reader(force_reload)
202
+
210
203
  if Bullet.start?
211
204
  if @owner.class.name !~ /^HABTM_/ && !@inversed
212
205
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
206
+
213
207
  if Bullet::Detector::NPlusOneQuery.impossible?(@owner)
214
208
  Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
215
209
  else
@@ -234,9 +228,7 @@ module Bullet
234
228
  alias_method :origin_count_records, :count_records
235
229
  def count_records
236
230
  result = has_cached_counter?
237
- if Bullet.start? && !result
238
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
239
- end
231
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
240
232
  origin_count_records
241
233
  end
242
234
  end