acts_as_votable 0.13.1 → 0.14.0

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: 1d9154268f7a15b8f66a0dcf909ce0dffd9e675c97559924c653c3ba90f4cf14
4
- data.tar.gz: 3cf9b07d912de5732d8867ad1fb16394244857ce4fb150682154c5e4a6b3e715
3
+ metadata.gz: 716790eb29b78931fcc52052c68a260036354513ee02850f06fc4460812b2b0a
4
+ data.tar.gz: 06e8af46b169792a3f218666ef9ee73d41e781baae2c88a5ed0202aa151d9043
5
5
  SHA512:
6
- metadata.gz: 3c1c7c024425ec4e0a22432e820f6d47598d0b0adaef43930c37f9ea9fb9d7c832e831e60252b8545679d12125b9f4912e8cc14356ad34e32c26237ddfa0422c
7
- data.tar.gz: f36cbcdc97e3f03470227dc669ad9f992f09e8d2e7ff66c5f0bd986ace5677dddcbf1552e6ee69e18148628ad70e5d5cd55357f4048f6f7fb503eca0a5c5a13f
6
+ metadata.gz: 476384079c94b60160d19ececbc96aedd83a0b4cadbc7b17662cf630cd2cbcfaaed9c616a74a3e5e10a93c0ec692437628fe967c8712d1e39ee8282b3b210dc5
7
+ data.tar.gz: 84989f2e628bfb60a07e07696a903b383cc07f372ac9780c597dc56d7d64721f98fbf20d1d4f44106fc77463d9e52713254d624df5bea2da378ff76f66a7d633
@@ -25,6 +25,15 @@ jobs:
25
25
  - gemfiles/rails_6_1.gemfile
26
26
  continue-on-error:
27
27
  - false
28
+ include:
29
+ - ruby: "3.0"
30
+ gemfile: gemfiles/rails_6_1.gemfile
31
+ os: ubuntu
32
+ continue-on-error: false
33
+ - ruby: 3.1
34
+ gemfile: gemfiles/rails_7_0.gemfile
35
+ os: ubuntu
36
+ continue-on-error: false
28
37
 
29
38
  env:
30
39
  BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
@@ -41,4 +50,4 @@ jobs:
41
50
  - name: Test
42
51
  run: bundle exec rake spec
43
52
 
44
- # use this
53
+ # use this
data/Appraisals CHANGED
@@ -16,4 +16,9 @@ end
16
16
  appraise "rails-6-1" do
17
17
  gem "rails", "6.1.0"
18
18
  gem "sqlite3", "~> 1.4"
19
- end
19
+ end
20
+
21
+ appraise "rails-7-0" do
22
+ gem "rails", "~> 7.0.0"
23
+ gem "sqlite3", "~> 1.4"
24
+ end
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(:name => 'my post!')
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 :voter => @user3
70
- @post.vote_by :voter => @user4, :vote => 'bad'
71
- @post.vote_by :voter => @user5, :vote => 'like'
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,21 +86,21 @@ Revisiting the previous example of code.
86
86
  ```ruby
87
87
  # positive votes
88
88
  @post.liked_by @user1
89
- @post.vote_by :voter => @user3
90
- @post.vote_by :voter => @user5, :vote => 'like'
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 :voter => @user2, :vote => 'bad'
94
+ @post.vote_by voter: @user2, vote: 'bad'
95
95
 
96
96
  # tally them up!
97
97
  @post.votes_for.size # => 5
98
- @post.weighted_total => 5
98
+ @post.weighted_total # => 5
99
99
  @post.get_likes.size # => 3
100
100
  @post.get_upvotes.size # => 3
101
101
  @post.get_dislikes.size # => 2
102
102
  @post.get_downvotes.size # => 2
103
- @post.weighted_score => 1
103
+ @post.weighted_score # => 1
104
104
  ```
105
105
 
106
106
  Active Record scopes are provided to make life easier.
@@ -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, :vote_scope => 'rank'
146
- @post.vote_by :voter => @user3, :vote_scope => 'rank'
147
- @post.vote_by :voter => @user5, :vote => 'like', :vote_scope => 'rank'
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, :vote_scope => 'rank'
151
- @post.vote_by :voter => @user2, :vote => 'bad', :vote_scope => 'rank'
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(: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
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 :voter => @user1, :vote_scope => 'week'
163
- @post.vote_by :voter => @user1, :vote_scope => 'month'
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(:vote_scope => 'week').size # => 1
167
- @post.find_votes_for(:vote_scope => 'month').size # => 1
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, :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
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, :vote_scope => 'rank', :vote_weight => 1
182
- @post.vote_by :voter => @user2, :vote => 'bad', :vote_scope => 'rank', :vote_weight => 3
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(: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
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, :duplicate => true
304
+ @hat.vote_by voter: @user, duplicate: true
305
305
  ```
306
306
 
307
307
  ## Caching
@@ -342,6 +342,9 @@ class AddCachedVotesToPosts < ActiveRecord::Migration
342
342
  t.integer :cached_weighted_subscribe_score, default: 0
343
343
  t.integer :cached_weighted_subscribe_total, default: 0
344
344
  t.float :cached_weighted_subscribe_average, default: 0.0
345
+
346
+ # Uncomment this line to force caching of existing scoped votes
347
+ # Post.find_each { |p| p.update_cached_votes("subscribe") }
345
348
  end
346
349
  end
347
350
  end
@@ -352,7 +355,7 @@ end
352
355
  Order by average rating:
353
356
 
354
357
  ```ruby
355
- Post.order(:cached_weighted_average => :desc)
358
+ Post.order(cached_weighted_average: :desc)
356
359
  ```
357
360
 
358
361
  Display average rating:
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.0.0"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ gemspec path: "../"
@@ -10,7 +10,6 @@ module ActsAsVotable
10
10
  end
11
11
 
12
12
  def acts_as_votable(args = {})
13
- require "acts_as_votable/votable"
14
13
  include ActsAsVotable::Votable
15
14
 
16
15
  if args.key?(:cacheable_strategy) && !ALLOWED_CACHEABLE_STRATEGIES.include?(args[:cacheable_strategy])
@@ -8,7 +8,6 @@ module ActsAsVotable
8
8
  end
9
9
 
10
10
  def acts_as_voter(*_args)
11
- require "acts_as_votable/voter"
12
11
  include ActsAsVotable::Voter
13
12
 
14
13
  class_eval do
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsVotable
4
+ module Extenders
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :"Votable"
8
+ autoload :"Voter"
9
+ autoload :"Controller"
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActsAsVotable
4
+ module Helpers
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :"Words"
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsVotable
4
- VERSION = "0.13.1"
4
+ VERSION = "0.14.0"
5
5
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "acts_as_votable/helpers/words"
4
- require "acts_as_votable/cacheable"
5
4
 
6
5
  module ActsAsVotable
7
6
  module Votable
@@ -2,20 +2,26 @@
2
2
 
3
3
  require "active_record"
4
4
  require "active_support/inflector"
5
+ require "active_support/dependencies/autoload"
5
6
 
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
8
 
8
9
  module ActsAsVotable
10
+ extend ActiveSupport::Autoload
11
+
12
+ autoload :Votable
13
+ autoload :Vote
14
+ autoload :Voter
15
+ autoload :Cacheable
16
+ autoload :Extenders
17
+ autoload :Helpers
18
+
9
19
  if defined?(ActiveRecord::Base)
10
- require "acts_as_votable/extenders/votable"
11
- require "acts_as_votable/extenders/voter"
12
- require "acts_as_votable/vote"
13
20
  ActiveRecord::Base.extend ActsAsVotable::Extenders::Votable
14
21
  ActiveRecord::Base.extend ActsAsVotable::Extenders::Voter
15
22
  end
16
23
  end
17
24
 
18
- require "acts_as_votable/extenders/controller"
19
25
  ActiveSupport.on_load(:action_controller) do
20
26
  include ActsAsVotable::Extenders::Controller
21
27
  end
@@ -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, :polymorphic => true
6
- t.references :voter, :polymorphic => true
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.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-19 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -118,11 +118,14 @@ files:
118
118
  - gemfiles/rails_6.gemfile
119
119
  - gemfiles/rails_6_1.gemfile
120
120
  - gemfiles/rails_6_rc1.gemfile
121
+ - gemfiles/rails_7_0.gemfile
121
122
  - lib/acts_as_votable.rb
122
123
  - lib/acts_as_votable/cacheable.rb
124
+ - lib/acts_as_votable/extenders.rb
123
125
  - lib/acts_as_votable/extenders/controller.rb
124
126
  - lib/acts_as_votable/extenders/votable.rb
125
127
  - lib/acts_as_votable/extenders/voter.rb
128
+ - lib/acts_as_votable/helpers.rb
126
129
  - lib/acts_as_votable/helpers/words.rb
127
130
  - lib/acts_as_votable/version.rb
128
131
  - lib/acts_as_votable/votable.rb
@@ -152,7 +155,7 @@ homepage: http://rubygems.org/gems/acts_as_votable
152
155
  licenses:
153
156
  - MIT
154
157
  metadata: {}
155
- post_install_message:
158
+ post_install_message:
156
159
  rdoc_options: []
157
160
  require_paths:
158
161
  - lib
@@ -167,8 +170,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
170
  - !ruby/object:Gem::Version
168
171
  version: '0'
169
172
  requirements: []
170
- rubygems_version: 3.2.2
171
- signing_key:
173
+ rubyforge_project:
174
+ rubygems_version: 2.7.6
175
+ signing_key:
172
176
  specification_version: 4
173
177
  summary: Rails gem to allowing records to be votable
174
178
  test_files: