custom_counter_cache 0.2.3 → 0.2.4
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/version.rb +1 -1
- data/test/test_helper.rb +12 -3
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b8cf04cebca60ef8b7cb77c5c54f0392c682e3a
|
4
|
+
data.tar.gz: 26aa1c6f245700136fe05a317ca2f7838b11ed57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faedbd90dd2d0c094d53f0e6742453fcde890e69da1dbc554d96d0e19f2d6b009d4adcafc040a441f078ee11f93fd45a354f2fcd13b6da98c3e0c79700e7b630
|
7
|
+
data.tar.gz: f843efb8ff01722e9cc5e064f8c0d9c27392508b7559037ee6ee751b3537bdc35342377e38df64f82b10bfb59d35024d4926c35cecd726ded9c13d62fec4babd
|
data/test/test_helper.rb
CHANGED
@@ -44,6 +44,15 @@ end
|
|
44
44
|
class ApplicationRecord < ActiveRecord::Base
|
45
45
|
self.abstract_class = true
|
46
46
|
include CustomCounterCache::Model
|
47
|
+
@@rails_5_1_or_newer = ActiveModel.version >= Gem::Version.new('5.1.0')
|
48
|
+
|
49
|
+
def saved_change_to_attribute_compat?(attr)
|
50
|
+
if @@rails_5_1_or_newer
|
51
|
+
saved_change_to_attribute?(attr)
|
52
|
+
else
|
53
|
+
attribute_changed?(attr)
|
54
|
+
end
|
55
|
+
end
|
47
56
|
end
|
48
57
|
|
49
58
|
class User < ApplicationRecord
|
@@ -55,7 +64,7 @@ end
|
|
55
64
|
|
56
65
|
class Article < ApplicationRecord
|
57
66
|
belongs_to :user
|
58
|
-
update_counter_cache :user, :published_count, if: Proc.new { |article| article.
|
67
|
+
update_counter_cache :user, :published_count, if: Proc.new { |article| article.saved_change_to_attribute_compat?(:state) }
|
59
68
|
has_many :comments, as: :commentable, dependent: :destroy
|
60
69
|
define_counter_cache :comments_count do |article|
|
61
70
|
article.comments.where(state: "published").count
|
@@ -64,7 +73,7 @@ end
|
|
64
73
|
|
65
74
|
class Comment < ApplicationRecord
|
66
75
|
belongs_to :commentable, polymorphic: true
|
67
|
-
update_counter_cache :commentable, :comments_count, if: Proc.new { |comment| comment.
|
76
|
+
update_counter_cache :commentable, :comments_count, if: Proc.new { |comment| comment.saved_change_to_attribute_compat?(:state) }
|
68
77
|
end
|
69
78
|
|
70
79
|
class Counter < ApplicationRecord
|
@@ -87,7 +96,7 @@ end
|
|
87
96
|
class Ball < ApplicationRecord
|
88
97
|
belongs_to :box
|
89
98
|
scope :green, lambda { where(color: 'green') }
|
90
|
-
update_counter_cache :box, :green_balls_count, if: Proc.new { |ball| ball.
|
99
|
+
update_counter_cache :box, :green_balls_count, if: Proc.new { |ball| ball.saved_change_to_attribute_compat?(:color) }
|
91
100
|
update_counter_cache :box, :lifetime_balls_count, except: [:update, :destroy]
|
92
101
|
update_counter_cache :box, :destroyed_balls_count, only: [:destroy]
|
93
102
|
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.4
|
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: 2019-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.3.3
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.4.0
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 1.3.3
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.4.0
|
41
47
|
description: ''
|
42
48
|
email: cedric@howe.net
|
43
49
|
executables: []
|
@@ -75,5 +81,5 @@ specification_version: 4
|
|
75
81
|
summary: Custom counter_cache functionality that supports conditions and multiple
|
76
82
|
models.
|
77
83
|
test_files:
|
78
|
-
- test/counter_test.rb
|
79
84
|
- test/test_helper.rb
|
85
|
+
- test/counter_test.rb
|