counter_culture 3.9.0 → 3.10.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/counter_culture/counter.rb +46 -0
- data/lib/counter_culture/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc2af460731ae5d0d71c452bff1969ede450961b0383de35624015058e73bbce
|
|
4
|
+
data.tar.gz: fe4cd5de448b52f11b2b5d9409202ad115bb6e87d5008ed83eb3708fbd177745
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 360b2c83a7e377c2a9974cfbd812d5df0f0d3921c93aabf5b4c0426e5f7aab156fe1cd7350607be17694b243f6cc823000b8eb2bb342fb65401ce9071dcc688e
|
|
7
|
+
data.tar.gz: 39a199f34ca2275c4804ab1f03a0dac80105675ef43dc473f3d9d4c479b57eb7088d32a36a67a47df00ae26e1d81d3454cf0de465209d357c181cca66de18d1c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## 3.10.2 (June 24, 2025)
|
|
2
|
+
|
|
3
|
+
Bugfixes:
|
|
4
|
+
- Fix incorrect in-memory counter updates on `belongs_to` association (#415)
|
|
5
|
+
|
|
6
|
+
## 3.10.1 (April 30, 2025)
|
|
7
|
+
|
|
8
|
+
Bugfixes:
|
|
9
|
+
- Fix issue when using `delegate` instead of `has_many :through` (#411)
|
|
10
|
+
|
|
11
|
+
## 3.10.0 (April 15, 2025)
|
|
12
|
+
|
|
13
|
+
New features:
|
|
14
|
+
- Update counter cache values without requiring a reload (#407)
|
|
15
|
+
|
|
1
16
|
## 3.9.0 (March 20, 2025)
|
|
2
17
|
|
|
3
18
|
New features:
|
|
@@ -138,6 +138,9 @@ module CounterCulture
|
|
|
138
138
|
unless Thread.current[:aggregate_counter_updates]
|
|
139
139
|
execute_now_or_after_commit(obj) do
|
|
140
140
|
klass.where(primary_key => id_to_change).update_all updates.join(', ')
|
|
141
|
+
unless options[:was]
|
|
142
|
+
assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
|
|
143
|
+
end
|
|
141
144
|
end
|
|
142
145
|
end
|
|
143
146
|
end
|
|
@@ -365,6 +368,49 @@ module CounterCulture
|
|
|
365
368
|
obj.public_send("#{attr}#{changes_method}")
|
|
366
369
|
end
|
|
367
370
|
|
|
371
|
+
# update associated object counter attribute
|
|
372
|
+
def assign_to_associated_object(obj, relation, change_counter_column, operator, delta_magnitude)
|
|
373
|
+
association_name = relation_reflect(relation).name
|
|
374
|
+
|
|
375
|
+
association_object = association_object_for_assign(obj, association_name)
|
|
376
|
+
return if association_object.blank?
|
|
377
|
+
|
|
378
|
+
association_object.assign_attributes(
|
|
379
|
+
change_counter_column =>
|
|
380
|
+
association_object_new_counter(association_object, change_counter_column, operator, delta_magnitude)
|
|
381
|
+
)
|
|
382
|
+
association_object_clear_change(association_object, change_counter_column)
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
def association_object_for_assign(obj, association_name)
|
|
386
|
+
if obj.class.reflect_on_all_associations.
|
|
387
|
+
find { |assoc| assoc.name.to_sym == association_name.to_sym }.
|
|
388
|
+
blank?
|
|
389
|
+
# This means that this isn't defined as an association; either it
|
|
390
|
+
# doesn't exist at all, or it uses delegate. In either case, we can't
|
|
391
|
+
# update the count this way.
|
|
392
|
+
return
|
|
393
|
+
end
|
|
394
|
+
if !obj.association(association_name).loaded?
|
|
395
|
+
# If the association isn't loaded, no need to update the count
|
|
396
|
+
return
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
obj.public_send(association_name)
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
def association_object_clear_change(association_object, change_counter_column)
|
|
403
|
+
if ACTIVE_RECORD_VERSION >= Gem::Version.new("6.1.0")
|
|
404
|
+
association_object.public_send(:"clear_#{change_counter_column}_change")
|
|
405
|
+
else
|
|
406
|
+
association_object.send(:clear_attribute_change, change_counter_column)
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def association_object_new_counter(association_object, change_counter_column, operator, delta_magnitude)
|
|
411
|
+
(association_object.public_send(change_counter_column) || 0).public_send(operator, delta_magnitude)
|
|
412
|
+
end
|
|
413
|
+
|
|
368
414
|
def assemble_money_counter_update(klass, id_to_change, quoted_column, operator, delta_magnitude)
|
|
369
415
|
counter_update_snippet(
|
|
370
416
|
"#{quoted_column} = COALESCE(CAST(#{quoted_column} as NUMERIC), 0)",
|
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.
|
|
4
|
+
version: 3.10.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: 2025-
|
|
11
|
+
date: 2025-06-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|