custom_counter_cache 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/custom_counter_cache/model.rb +6 -3
- data/lib/custom_counter_cache/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 400ada3c3c7715a41f90c457b92c2657c1e78aba
|
4
|
+
data.tar.gz: 77fe16bc8457b85e482fdacd12a0b98f9c68c652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8fa7062dde06853f72ec4879d90c4ea4c5fda69cf49274166b8ca24aa91660dfed29bdf55bb6fdad1d8a5be139d683cd80efc66767a65bb3d611fa3b83ff0ef
|
7
|
+
data.tar.gz: a1626989296134b9c7cc5c30dba4eb32442932bfa54b9ba4d007a476df41ca40d2343d5c215b42896deb571838ac20d0109e9f4fd9b2dc871c4bab54eadc9ac5
|
@@ -53,10 +53,13 @@ module CustomCounterCache::Model
|
|
53
53
|
# define callback
|
54
54
|
define_method method_name do
|
55
55
|
# update old association
|
56
|
-
|
57
|
-
|
56
|
+
rails_5_1_or_newer = ActiveModel.version >= Gem::Version.new('5.1.0')
|
57
|
+
target_key = reflection.options[:polymorphic] ? "#{association}_type" : foreign_key
|
58
|
+
target_changed = rails_5_1_or_newer ? send("saved_change_to_#{target_key}?") : send("#{target_key}_changed?")
|
59
|
+
if target_changed
|
60
|
+
old_id = rails_5_1_or_newer ? send("#{target_key}_before_last_save") : send("#{target_key}_was")
|
58
61
|
klass = if reflection.options[:polymorphic]
|
59
|
-
(
|
62
|
+
( old_id || send("#{association}_type") ).constantize
|
60
63
|
else
|
61
64
|
reflection.klass
|
62
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_counter_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cedric Howe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -69,11 +69,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: 1.3.6
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project: custom_counter_cache
|
72
|
-
rubygems_version: 2.6.
|
72
|
+
rubygems_version: 2.6.13
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Custom counter_cache functionality that supports conditions and multiple
|
76
76
|
models.
|
77
77
|
test_files:
|
78
|
-
- test/test_helper.rb
|
79
78
|
- test/counter_test.rb
|
79
|
+
- test/test_helper.rb
|