counter_culture 3.13.1 → 3.13.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9731db7c2d482e50fef56c6bac5e7c9e1697ac1f2f4f20ff9bb819088d77e843
4
- data.tar.gz: 1fd97cbd3f4642eb8ff9ae375e1d50d244f1e0f034fe2fcd72e0593cd03641f5
3
+ metadata.gz: 8dcb5f1c57a5fda38de103fdcdf767e990f507b994c1d2e59debdbde0b1f3ef3
4
+ data.tar.gz: 8945d83862559fb693b79d1837507c23f978828e3d9c377f2d4cacf67d4843cc
5
5
  SHA512:
6
- metadata.gz: f38aec03d1ad8259e26f26a6b51301e01f34a3ccc88c11086b0bc26eeecbfbd423c6e58913e1315918eb50368c3a07b50d22f5f3463ed673749e5ebc1df237ba
7
- data.tar.gz: 6f277537ab3465cf2e3ec6fdef625f611ba55cfc7285c438a6e0e8027dc634df84356004ec6c2569adb365ef95652cfb2f008b958c08948e2598dabce93015a1
6
+ metadata.gz: 398000f43d6feb9165c54ec2e3614b65bb9f384e8c8f9693d6956ee9e22d2e2eec6bad28b7cdab21b1fd2543fbee05f3f04d7f697a60a740fbdd00e20e960d9b
7
+ data.tar.gz: 7a8e5b137d1266161ff9cb3569005f2acd147829656fc66b1aabcb0bf0d3e0a823bc3398b0b6573c6b01e394f996436a53861949e09560ca5219b414ad67193b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.13.2 (June 25, 2026)
2
+
3
+ Bugfixes:
4
+ - Fix multi-level counter caches not being updated in memory when creating or destroying records (#432)
5
+
1
6
  ## 3.13.1 (April 20, 2026)
2
7
 
3
8
  Bugfixes:
@@ -410,9 +410,7 @@ module CounterCulture
410
410
 
411
411
  # update associated object counter attribute
412
412
  def assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
413
- association_name = relation_reflect(relation).name
414
-
415
- association_object = association_object_for_assign(obj, association_name)
413
+ association_object = association_object_for_assign(obj, relation)
416
414
  return if association_object.blank? || association_object.frozen?
417
415
 
418
416
  association_object.assign_attributes(
@@ -422,21 +420,23 @@ module CounterCulture
422
420
  association_object_clear_change(association_object, change_counter_column)
423
421
  end
424
422
 
425
- def association_object_for_assign(obj, association_name)
426
- if obj.class.reflect_on_all_associations.
427
- find { |assoc| assoc.name.to_sym == association_name.to_sym }.
428
- blank?
429
- # This means that this isn't defined as an association; either it
430
- # doesn't exist at all, or it uses delegate. In either case, we can't
431
- # update the count this way.
432
- return
433
- end
434
- if !obj.association(association_name).loaded?
435
- # If the association isn't loaded, no need to update the count
436
- return
423
+ def association_object_for_assign(obj, relation)
424
+ relation = relation.is_a?(Enumerable) ? relation.dup : [relation]
425
+
426
+ while !obj.nil? && relation.size > 0
427
+ cur_relation = relation.shift
428
+ # This isn't an association (e.g. it uses delegate), so we can't update the count this way
429
+ return nil if obj.class.reflect_on_association(cur_relation).nil?
430
+
431
+ if !obj.association(cur_relation).loaded?
432
+ # If the association isn't loaded, no need to update the count
433
+ return nil
434
+ end
435
+
436
+ obj = obj.public_send(cur_relation)
437
437
  end
438
438
 
439
- obj.public_send(association_name)
439
+ obj
440
440
  end
441
441
 
442
442
  def association_object_clear_change(association_object, change_counter_column)
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.13.1'.freeze
2
+ VERSION = '3.13.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.1
4
+ version: 3.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-20 00:00:00.000000000 Z
11
+ date: 2026-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord