acts_as_votable 0.13.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6493d9c06d86a52dc314e405d87f1cb571d5af56d5e2a0b143e700f864d2ba24
|
4
|
+
data.tar.gz: e832c7530a935db303318540558b8de0c7992e6be33c31efc6dd69fecdd56092
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba57359f7c30c08272f97a5c066a8b0f9ec8eb01c12966abf589a7d005542910a3b7fb3162bdd7eb3924f38bd081bafb174e73038a107448d7c1da7c7b1299b
|
7
|
+
data.tar.gz: f63bc1fbca5eb2fca9bd8a9182eb9ae669975f01edaa2e6beb0cc82399ff26ccb18e89c71e4659eea2a29532f6003d8c48748b1ea4be1f88fad3de5e7f3e978b
|
data/README.md
CHANGED
@@ -51,7 +51,7 @@ class Post < ApplicationRecord
|
|
51
51
|
acts_as_votable
|
52
52
|
end
|
53
53
|
|
54
|
-
@post = Post.new(:
|
54
|
+
@post = Post.new(name: 'my post!')
|
55
55
|
@post.save
|
56
56
|
|
57
57
|
@post.liked_by @user
|
@@ -66,9 +66,9 @@ more natural calls are the first few examples.
|
|
66
66
|
```ruby
|
67
67
|
@post.liked_by @user1
|
68
68
|
@post.downvote_from @user2
|
69
|
-
@post.vote_by :
|
70
|
-
@post.vote_by :
|
71
|
-
@post.vote_by :
|
69
|
+
@post.vote_by voter: @user3
|
70
|
+
@post.vote_by voter: @user4, vote: 'bad'
|
71
|
+
@post.vote_by voter: @user5, vote: 'like'
|
72
72
|
```
|
73
73
|
|
74
74
|
By default all votes are positive, so `@user3` has cast a 'good' vote for `@post`.
|
@@ -86,12 +86,12 @@ Revisiting the previous example of code.
|
|
86
86
|
```ruby
|
87
87
|
# positive votes
|
88
88
|
@post.liked_by @user1
|
89
|
-
@post.vote_by :
|
90
|
-
@post.vote_by :
|
89
|
+
@post.vote_by voter: @user3
|
90
|
+
@post.vote_by voter: @user5, vote: 'like'
|
91
91
|
|
92
92
|
# negative votes
|
93
93
|
@post.downvote_from @user2
|
94
|
-
@post.vote_by :
|
94
|
+
@post.vote_by voter: @user2, vote: 'bad'
|
95
95
|
|
96
96
|
# tally them up!
|
97
97
|
@post.votes_for.size # => 5
|
@@ -142,29 +142,29 @@ You can add a scope to your vote
|
|
142
142
|
|
143
143
|
```ruby
|
144
144
|
# positive votes
|
145
|
-
@post.liked_by @user1, :
|
146
|
-
@post.vote_by :
|
147
|
-
@post.vote_by :
|
145
|
+
@post.liked_by @user1, vote_scope: 'rank'
|
146
|
+
@post.vote_by voter: @user3, vote_scope: 'rank'
|
147
|
+
@post.vote_by voter: @user5, vote: 'like', vote_scope: 'rank'
|
148
148
|
|
149
149
|
# negative votes
|
150
|
-
@post.downvote_from @user2, :
|
151
|
-
@post.vote_by :
|
150
|
+
@post.downvote_from @user2, vote_scope: 'rank'
|
151
|
+
@post.vote_by voter: @user2, vote: 'bad', vote_scope: 'rank'
|
152
152
|
|
153
153
|
# tally them up!
|
154
|
-
@post.find_votes_for(:
|
155
|
-
@post.get_likes(:
|
156
|
-
@post.get_upvotes(:
|
157
|
-
@post.get_dislikes(:
|
158
|
-
@post.get_downvotes(:
|
154
|
+
@post.find_votes_for(vote_scope: 'rank').size # => 5
|
155
|
+
@post.get_likes(vote_scope: 'rank').size # => 3
|
156
|
+
@post.get_upvotes(vote_scope: 'rank').size # => 3
|
157
|
+
@post.get_dislikes(vote_scope: 'rank').size # => 2
|
158
|
+
@post.get_downvotes(vote_scope: 'rank').size # => 2
|
159
159
|
|
160
160
|
# votable model can be voted under different scopes
|
161
161
|
# by the same user
|
162
|
-
@post.vote_by :
|
163
|
-
@post.vote_by :
|
162
|
+
@post.vote_by voter: @user1, vote_scope: 'week'
|
163
|
+
@post.vote_by voter: @user1, vote_scope: 'month'
|
164
164
|
|
165
165
|
@post.votes_for.size # => 2
|
166
|
-
@post.find_votes_for(:
|
167
|
-
@post.find_votes_for(:
|
166
|
+
@post.find_votes_for(vote_scope: 'week').size # => 1
|
167
|
+
@post.find_votes_for(vote_scope: 'month').size # => 1
|
168
168
|
```
|
169
169
|
|
170
170
|
### Adding weights to your votes
|
@@ -173,20 +173,20 @@ You can add weight to your vote. The default value is 1.
|
|
173
173
|
|
174
174
|
```ruby
|
175
175
|
# positive votes
|
176
|
-
@post.liked_by @user1, :
|
177
|
-
@post.vote_by :
|
178
|
-
@post.vote_by :
|
176
|
+
@post.liked_by @user1, vote_weight: 1
|
177
|
+
@post.vote_by voter: @user3, vote_weight: 2
|
178
|
+
@post.vote_by voter: @user5, vote: 'like', vote_scope: 'rank', vote_weight: 3
|
179
179
|
|
180
180
|
# negative votes
|
181
|
-
@post.downvote_from @user2, :
|
182
|
-
@post.vote_by :
|
181
|
+
@post.downvote_from @user2, vote_scope: 'rank', vote_weight: 1
|
182
|
+
@post.vote_by voter: @user2, vote: 'bad', vote_scope: 'rank', vote_weight: 3
|
183
183
|
|
184
184
|
# tally them up!
|
185
|
-
@post.find_votes_for(:
|
186
|
-
@post.get_likes(:
|
187
|
-
@post.get_upvotes(:
|
188
|
-
@post.get_dislikes(:
|
189
|
-
@post.get_downvotes(:
|
185
|
+
@post.find_votes_for(vote_scope: 'rank').sum(:vote_weight) # => 6
|
186
|
+
@post.get_likes(vote_scope: 'rank').sum(:vote_weight) # => 6
|
187
|
+
@post.get_upvotes(vote_scope: 'rank').sum(:vote_weight) # => 6
|
188
|
+
@post.get_dislikes(vote_scope: 'rank').sum(:vote_weight) # => 4
|
189
|
+
@post.get_downvotes(vote_scope: 'rank').sum(:vote_weight) # => 4
|
190
190
|
```
|
191
191
|
|
192
192
|
### The Voter
|
@@ -301,7 +301,7 @@ To permit duplicates entries of a same voter, use option duplicate. Also notice
|
|
301
301
|
will limit some other methods that didn't deal with multiples votes, in this case, the last vote will be considered.
|
302
302
|
|
303
303
|
```ruby
|
304
|
-
@hat.vote_by voter: @user, :
|
304
|
+
@hat.vote_by voter: @user, duplicate: true
|
305
305
|
```
|
306
306
|
|
307
307
|
## Caching
|
@@ -352,7 +352,7 @@ end
|
|
352
352
|
Order by average rating:
|
353
353
|
|
354
354
|
```ruby
|
355
|
-
Post.order(:
|
355
|
+
Post.order(cached_weighted_average: :desc)
|
356
356
|
```
|
357
357
|
|
358
358
|
Display average rating:
|
@@ -38,6 +38,8 @@ module ActsAsVotable
|
|
38
38
|
"[4.2]"
|
39
39
|
elsif rails6?
|
40
40
|
"[6.0]"
|
41
|
+
elsif rails7?
|
42
|
+
"[7.0]"
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -48,5 +50,9 @@ module ActsAsVotable
|
|
48
50
|
def rails6?
|
49
51
|
Rails.version.start_with? "6"
|
50
52
|
end
|
53
|
+
|
54
|
+
def rails7?
|
55
|
+
Rails.version.start_with? "7"
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
@@ -2,8 +2,8 @@ class ActsAsVotableMigration < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def self.up
|
3
3
|
create_table :votes do |t|
|
4
4
|
|
5
|
-
t.references :votable, :
|
6
|
-
t.references :voter, :
|
5
|
+
t.references :votable, polymorphic: true
|
6
|
+
t.references :voter, polymorphic: true
|
7
7
|
|
8
8
|
t.boolean :vote_flag
|
9
9
|
t.string :vote_scope
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_votable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|