bullet 7.1.0 → 7.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3556ad95bac8e87086710acf1c5b7ea5aa8252ee83ab3b20dfb4ec9e06a06474
4
- data.tar.gz: 5d3695f3e2ab1ff51232e56d056aaf994630d465f5902106ceef125a7c6426d9
3
+ metadata.gz: 7c62bb5eb8bdfdb62ce49a79609ce7665d6af8be0f7dede7361379597415dcd4
4
+ data.tar.gz: 8da00673c07b79eb6dbf7b061aaf6dd0208fd0be841a96c3169ba919259fcf82
5
5
  SHA512:
6
- metadata.gz: 150e4ba5ae1900d1e50b87cfed8f325ff2615bbe613e908bc5e253d7072a0018869a6a67ca311a3f22cd190cadc87882e99700e0f9ae1e54277b64ddd0d2fe45
7
- data.tar.gz: cf3c2bf147e67915dd46670a8cf2b77b90c236fddca56fe1663ff62d8bf10a1a10506ee54773a28b7759d892ed6ed7fcdd7e0952d6b67ec8074b5a66abce0a8f
6
+ metadata.gz: f33ad269a72ba293680c65ed460ef4e598446eebf62c82d79879de03b3cb52098f27499cab681facec3fdc3a3d6f937d064c21621aefcc69edcf499a52680838
7
+ data.tar.gz: 4a386c2bda2cdea90926ce9ff8bca0932954507ac4fa1e5986a356d869c3fb410b48708a5de843fb0e1f822f744ef1cf26dcecc9036ad3036f774ffad1c6e84e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## Next Release
2
2
 
3
+ ## 7.1.2 (10/13/2023)
4
+
5
+ * Handle Rails 7.1 composite primary keys
6
+
7
+ ## 7.1.1 (10/07/2023)
8
+
9
+ * Add support for `Content-Security-Policy-Report-Only` nonces
10
+ * Fix count method signature
11
+
3
12
  ## 7.1.0 (10/06/2023)
4
13
 
5
14
  * Support rails 7.1
@@ -178,11 +178,11 @@ module Bullet
178
178
  end
179
179
 
180
180
  ::ActiveRecord::Associations::CollectionProxy.class_eval do
181
- def count
181
+ def count(column_name = nil, options = {})
182
182
  if Bullet.start?
183
183
  Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
184
184
  end
185
- super
185
+ super(column_name, options)
186
186
  end
187
187
  end
188
188
  end
@@ -170,11 +170,11 @@ module Bullet
170
170
  end
171
171
 
172
172
  ::ActiveRecord::Associations::CollectionProxy.class_eval do
173
- def count
173
+ def count(column_name = nil, options = {})
174
174
  if Bullet.start?
175
175
  Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
176
176
  end
177
- super
177
+ super(column_name, options)
178
178
  end
179
179
  end
180
180
  end
@@ -235,11 +235,11 @@ module Bullet
235
235
  end
236
236
 
237
237
  ::ActiveRecord::Associations::CollectionProxy.class_eval do
238
- def count
238
+ def count(column_name = nil, options = {})
239
239
  if Bullet.start?
240
240
  Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
241
241
  end
242
- super
242
+ super(column_name, options)
243
243
  end
244
244
  end
245
245
  end
@@ -265,7 +265,10 @@ module Bullet
265
265
  Module.new do
266
266
  def count
267
267
  if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
268
- Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
268
+ Bullet::Detector::CounterCache.add_counter_cache(
269
+ proxy_association.owner,
270
+ proxy_association.reflection.name
271
+ )
269
272
  end
270
273
  super
271
274
  end
@@ -245,11 +245,14 @@ module Bullet
245
245
 
246
246
  ::ActiveRecord::Associations::CollectionProxy.prepend(
247
247
  Module.new do
248
- def count
248
+ def count(column_name = nil)
249
249
  if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
250
- Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
250
+ Bullet::Detector::CounterCache.add_counter_cache(
251
+ proxy_association.owner,
252
+ proxy_association.reflection.name
253
+ )
251
254
  end
252
- super
255
+ super(column_name)
253
256
  end
254
257
  end
255
258
  )
@@ -274,7 +274,10 @@ module Bullet
274
274
  Module.new do
275
275
  def count
276
276
  if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
277
- Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
277
+ Bullet::Detector::CounterCache.add_counter_cache(
278
+ proxy_association.owner,
279
+ proxy_association.reflection.name
280
+ )
278
281
  end
279
282
  super
280
283
  end
@@ -272,11 +272,14 @@ module Bullet
272
272
 
273
273
  ::ActiveRecord::Associations::CollectionProxy.prepend(
274
274
  Module.new do
275
- def count
275
+ def count(column_name = nil)
276
276
  if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
277
- Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
277
+ Bullet::Detector::CounterCache.add_counter_cache(
278
+ proxy_association.owner,
279
+ proxy_association.reflection.name
280
+ )
278
281
  end
279
- super
282
+ super(column_name)
280
283
  end
281
284
  end
282
285
  )
@@ -65,7 +65,9 @@ module Bullet
65
65
  def call
66
66
  if Bullet.start?
67
67
  @preloaders.each do |preloader|
68
- preloader.records.each { |record| Bullet::Detector::Association.add_object_associations(record, preloader.associations) }
68
+ preloader.records.each { |record|
69
+ Bullet::Detector::Association.add_object_associations(record, preloader.associations)
70
+ }
69
71
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(preloader.records, preloader.associations)
70
72
  end
71
73
  end
@@ -80,7 +82,9 @@ module Bullet
80
82
  if Bullet.start?
81
83
  reflection_records.compact!
82
84
  if reflection_records.first.class.name !~ /^HABTM_/
83
- reflection_records.each { |record| Bullet::Detector::Association.add_object_associations(record, reflection.name) }
85
+ reflection_records.each { |record|
86
+ Bullet::Detector::Association.add_object_associations(record, reflection.name)
87
+ }
84
88
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(reflection_records, reflection.name)
85
89
  end
86
90
  end
@@ -284,11 +288,14 @@ module Bullet
284
288
 
285
289
  ::ActiveRecord::Associations::CollectionProxy.prepend(
286
290
  Module.new do
287
- def count
291
+ def count(column_name = nil)
288
292
  if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
289
- Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
293
+ Bullet::Detector::CounterCache.add_counter_cache(
294
+ proxy_association.owner,
295
+ proxy_association.reflection.name
296
+ )
290
297
  end
291
- super
298
+ super(column_name)
292
299
  end
293
300
  end
294
301
  )
@@ -65,7 +65,9 @@ module Bullet
65
65
  def call
66
66
  if Bullet.start?
67
67
  @preloaders.each do |preloader|
68
- preloader.records.each { |record| Bullet::Detector::Association.add_object_associations(record, preloader.associations) }
68
+ preloader.records.each { |record|
69
+ Bullet::Detector::Association.add_object_associations(record, preloader.associations)
70
+ }
69
71
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(preloader.records, preloader.associations)
70
72
  end
71
73
  end
@@ -80,7 +82,9 @@ module Bullet
80
82
  if Bullet.start?
81
83
  reflection_records.compact!
82
84
  if reflection_records.first.class.name !~ /^HABTM_/
83
- reflection_records.each { |record| Bullet::Detector::Association.add_object_associations(record, reflection.name) }
85
+ reflection_records.each { |record|
86
+ Bullet::Detector::Association.add_object_associations(record, reflection.name)
87
+ }
84
88
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(reflection_records, reflection.name)
85
89
  end
86
90
  end
@@ -284,11 +288,14 @@ module Bullet
284
288
 
285
289
  ::ActiveRecord::Associations::CollectionProxy.prepend(
286
290
  Module.new do
287
- def count
291
+ def count(column_name = nil)
288
292
  if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
289
- Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
293
+ Bullet::Detector::CounterCache.add_counter_cache(
294
+ proxy_association.owner,
295
+ proxy_association.reflection.name
296
+ )
290
297
  end
291
- super
298
+ super(column_name)
292
299
  end
293
300
  end
294
301
  )
@@ -44,13 +44,10 @@ module Bullet
44
44
  unless obj.bullet_primary_key_value.nil?
45
45
  primary_key_values_are_empty = false
46
46
  end
47
- keys_joined += "#{(keys_joined.empty?? '' : ', ')}#{obj.bullet_key}"
47
+ keys_joined += "#{(keys_joined.empty? ? '' : ', ')}#{obj.bullet_key}"
48
48
  end
49
49
  unless class_names_match_regex || primary_key_values_are_empty
50
- Bullet.debug(
51
- 'Detector::NPlusOneQuery#add_possible_objects',
52
- "objects: #{keys_joined}"
53
- )
50
+ Bullet.debug('Detector::NPlusOneQuery#add_possible_objects', "objects: #{keys_joined}")
54
51
  objects.each { |object| possible_objects.add object.bullet_key }
55
52
  end
56
53
  end
@@ -65,7 +65,10 @@ module Bullet
65
65
  private
66
66
 
67
67
  def create_notification(callers, klazz, associations)
68
- notify_associations = Array.wrap(associations) - Bullet.get_safelist_associations(:unused_eager_loading, klazz)
68
+ notify_associations = Array.wrap(associations) - Bullet.get_safelist_associations(
69
+ :unused_eager_loading,
70
+ klazz
71
+ )
69
72
 
70
73
  if notify_associations.present?
71
74
  notice = Bullet::Notification::UnusedEagerLoading.new(callers, klazz, notify_associations)
@@ -9,11 +9,21 @@ class Object
9
9
  return if respond_to?(:persisted?) && !persisted?
10
10
 
11
11
  if self.class.respond_to?(:primary_keys) && self.class.primary_keys
12
- self.class.primary_keys.map { |primary_key| send primary_key }.join(',')
12
+ primary_key = self.class.primary_keys
13
13
  elsif self.class.respond_to?(:primary_key) && self.class.primary_key
14
- send self.class.primary_key
14
+ primary_key = self.class.primary_key
15
15
  else
16
- id
16
+ primary_key = :id
17
17
  end
18
+
19
+ bullet_join_potential_composite_primary_key(primary_key)
20
+ end
21
+
22
+ private
23
+
24
+ def bullet_join_potential_composite_primary_key(primary_keys)
25
+ return send(primary_keys) unless primary_keys.is_a?(Enumerable)
26
+
27
+ primary_keys.map { |primary_key| send primary_key }.join(',')
18
28
  end
19
29
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module Bullet
3
2
  module Mongoid
4
3
  def self.enable
@@ -23,6 +22,7 @@ module Bullet
23
22
 
24
23
  def each(&block)
25
24
  return to_enum unless block_given?
25
+
26
26
  records = []
27
27
  origin_each { |record| records << record }
28
28
  if records.length > 1
@@ -28,13 +28,13 @@ module Bullet
28
28
  def whoami
29
29
  @user ||=
30
30
  ENV['USER'].presence ||
31
- (
32
- begin
33
- `whoami`.chomp
34
- rescue StandardError
35
- ''
36
- end
37
- )
31
+ (
32
+ begin
33
+ `whoami`.chomp
34
+ rescue StandardError
35
+ ''
36
+ end
37
+ )
38
38
  @user.present? ? "user: #{@user}" : ''
39
39
  end
40
40
 
@@ -73,7 +73,8 @@ module Bullet
73
73
  end
74
74
 
75
75
  def associations_str
76
- ".includes(#{@associations.map { |a| a.to_s.to_sym }.inspect})"
76
+ ".includes(#{@associations.map { |a| a.to_s.to_sym }
77
+ .inspect})"
77
78
  end
78
79
  end
79
80
  end
data/lib/bullet/rack.rb CHANGED
@@ -49,6 +49,7 @@ module Bullet
49
49
  # response may be ["Not Found"], ["Move Permanently"], etc, but
50
50
  # those should not happen if the status is 200
51
51
  return true if !response.respond_to?(:body) && !response.respond_to?(:first)
52
+
52
53
  body = response_body(response)
53
54
  body.nil? || body.empty?
54
55
  end
@@ -135,7 +136,8 @@ module Bullet
135
136
  end
136
137
 
137
138
  def with_security_policy_nonce(headers)
138
- matched = (headers['Content-Security-Policy'] || '').match(NONCE_MATCHER)
139
+ csp = headers['Content-Security-Policy'] || headers['Content-Security-Policy-Report-Only'] || ''
140
+ matched = csp.match(NONCE_MATCHER)
139
141
  nonce = matched[:nonce] if matched
140
142
 
141
143
  if nonce
@@ -8,7 +8,8 @@ module Bullet
8
8
  end
9
9
 
10
10
  def similarly_associated(base, associations)
11
- @registry.select { |key, value| key.include?(base) && value == associations }.collect(&:first).flatten
11
+ @registry.select { |key, value| key.include?(base) && value == associations }
12
+ .collect(&:first).flatten
12
13
  end
13
14
  end
14
15
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "bundler"
3
4
 
4
5
  module Bullet
@@ -14,8 +15,8 @@ module Bullet
14
15
  caller_path = location_as_path(location)
15
16
  caller_path.include?(Bullet.app_root) && !caller_path.include?(vendor_root) &&
16
17
  !caller_path.include?(bundler_path) || Bullet.stacktrace_includes.any? { |include_pattern|
17
- pattern_matches?(location, include_pattern)
18
- }
18
+ pattern_matches?(location, include_pattern)
19
+ }
19
20
  end
20
21
  end
21
22
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullet
4
- VERSION = '7.1.0'
4
+ VERSION = '7.1.2'
5
5
  end
data/lib/bullet.rb CHANGED
@@ -43,7 +43,8 @@ module Bullet
43
43
  attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers, :always_append_html_body
44
44
 
45
45
  available_notifiers =
46
- UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
46
+ UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }
47
+ .map { |notifier| "#{notifier}=" }
47
48
  available_notifiers_options = { to: UniformNotifier }
48
49
  delegate(*available_notifiers, **available_notifiers_options)
49
50
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-06 00:00:00.000000000 Z
11
+ date: 2023-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport