custom_counter_cache 0.1.9 → 0.2.0
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/lib/custom_counter_cache/model.rb +0 -2
- data/lib/custom_counter_cache/version.rb +1 -1
- data/test/test_helper.rb +11 -6
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0df4c855c8d546d5ec7f81e536e317b1d222d53
|
4
|
+
data.tar.gz: 16859fbe11a54eb4aabdf53aadc9709e8355a8a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6797bf2591cd0d5926a3f6bb2021f14929ef6f52aac6771caff65093639983439136caf3c499887328744c796b57c43fa431d59d455bbad693613510004dd974
|
7
|
+
data.tar.gz: 91bdf24d3740327dce1cc354b4bf34e36421a19dcd83f832309109e7671a36e696ddcb7acbec7c0a12d6dce625a4d35e31adf799ce5511340ee8e757eb7b475a
|
data/test/test_helper.rb
CHANGED
@@ -39,14 +39,19 @@ ActiveRecord::Schema.define(version: 1) do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
class
|
42
|
+
class ApplicationRecord < ActiveRecord::Base
|
43
|
+
self.abstract_class = true
|
44
|
+
include CustomCounterCache::Model
|
45
|
+
end
|
46
|
+
|
47
|
+
class User < ApplicationRecord
|
43
48
|
has_many :articles, dependent: :destroy
|
44
49
|
define_counter_cache :published_count do |user|
|
45
50
|
user.articles.where(articles: { state: 'published' }).count
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
|
-
class Article <
|
54
|
+
class Article < ApplicationRecord
|
50
55
|
belongs_to :user
|
51
56
|
update_counter_cache :user, :published_count, if: Proc.new { |article| article.state_changed? }
|
52
57
|
has_many :comments, as: :commentable, dependent: :destroy
|
@@ -55,23 +60,23 @@ class Article < ActiveRecord::Base
|
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
|
-
class Comment <
|
63
|
+
class Comment < ApplicationRecord
|
59
64
|
belongs_to :commentable, polymorphic: true
|
60
65
|
update_counter_cache :commentable, :comments_count, if: Proc.new { |comment| comment.state_changed? }
|
61
66
|
end
|
62
67
|
|
63
|
-
class Counter <
|
68
|
+
class Counter < ApplicationRecord
|
64
69
|
belongs_to :countable, polymorphic: true
|
65
70
|
end
|
66
71
|
|
67
|
-
class Box <
|
72
|
+
class Box < ApplicationRecord
|
68
73
|
has_many :balls
|
69
74
|
define_counter_cache :green_balls_count do |box|
|
70
75
|
box.balls.green.count
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
74
|
-
class Ball <
|
79
|
+
class Ball < ApplicationRecord
|
75
80
|
belongs_to :box
|
76
81
|
scope :green, lambda { where(color: 'green') }
|
77
82
|
update_counter_cache :box, :green_balls_count, if: Proc.new { |ball| ball.color_changed? }
|
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.
|
4
|
+
version: 0.2.0
|
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: 2017-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,7 +69,7 @@ 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.
|
72
|
+
rubygems_version: 2.6.11
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Custom counter_cache functionality that supports conditions and multiple
|