custom_counter_cache 0.2.2 → 0.2.3

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
  SHA1:
3
- metadata.gz: 51f38aaeec8fe7a42868c8d1bb9da6335ad58232
4
- data.tar.gz: 1409e90333ee408e02c893d744e968e1ea56a919
3
+ metadata.gz: 400ada3c3c7715a41f90c457b92c2657c1e78aba
4
+ data.tar.gz: 77fe16bc8457b85e482fdacd12a0b98f9c68c652
5
5
  SHA512:
6
- metadata.gz: 903199c537808240f5d1fba9057277970bb6b0c0fdd8685690d9f16cbc23d1003d383ffcdd27f911ada7c720dfc038798e728641fcb2aa2ac2dc762450c9193e
7
- data.tar.gz: 7a19e2dd0d91060ab41ae8b98dfefcec4d2aa0ac7d01c019b26d2ccc4c5b1af48ede587c00e4fb8be724b945a178d9d5c2d8af97bfe4557def51a134753ec598
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
- if send("#{foreign_key}_changed?") || ( reflection.options[:polymorphic] && send("#{association}_type_changed?") )
57
- old_id = send("#{foreign_key}_was")
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
- ( send("#{association}_type_was") || send("#{association}_type") ).constantize
62
+ ( old_id || send("#{association}_type") ).constantize
60
63
  else
61
64
  reflection.klass
62
65
  end
@@ -1,5 +1,5 @@
1
1
  module CustomCounterCache
2
2
 
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
 
5
5
  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.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: 2017-11-17 00:00:00.000000000 Z
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.11
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