acts_as_favoritor 5.0.1 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/acts_as_favoritor/favoritable.rb +0 -2
- data/lib/acts_as_favoritor/favorite_scopes.rb +0 -2
- data/lib/acts_as_favoritor/favoritor.rb +8 -8
- data/lib/acts_as_favoritor/favoritor_lib.rb +2 -2
- data/lib/acts_as_favoritor/version.rb +1 -1
- data/lib/generators/templates/migration.rb.erb +4 -0
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 720e4ea66b88a043a1bcd46c702dc8aa445b20fe60517e978791d8c4bcbc90af
|
4
|
+
data.tar.gz: beb07b7607a369e302816b9e39b9dae5ec8ca488ff717ff3bdb3e3b96fea1227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1dc068b8f318a7141d2d695693245aef8aaf22ffecc2cb46484308fb9c0563cd1576d855113f336871cb4a6e7a20adf867c5b0629f7a04042fbd5862615a746
|
7
|
+
data.tar.gz: b736fbaa9e300ac44c9f83cbe99f780e8cfabcde661a9baf7bbef8a7fa88a28c61a022e8140d005269315b84524d8a69a549fa699da3a513221511613da28800
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ acts_as_favoritor is a Rubygem to allow any ActiveRecord model to associate any
|
|
4
4
|
|
5
5
|
You are able to differentiate followers, favorites, watchers, votes and whatever else you can imagine through a single relationship. This is accomplished by a double polymorphic relationship on the Favorite model. There is also built in support for blocking/un-blocking favorite records as well as caching.
|
6
6
|
|
7
|
+
[This Medium article](https://medium.com/swlh/add-dynamic-like-dislike-buttons-to-your-rails-6-application-ccce8a234c43) gives a good introduction to this gem.
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
You can add acts_as_favoritor to your `Gemfile` with:
|
@@ -145,7 +147,7 @@ Using scopes with `acts_as_favoritor` enables you to Follow, Watch, Favorite, [.
|
|
145
147
|
|
146
148
|
By default all of your favorites are scoped to `'favorite'`.
|
147
149
|
|
148
|
-
You can create new scopes on the fly. Every single method takes `scope`/`scopes` as an option which
|
150
|
+
You can create new scopes on the fly. Every single method takes `scope`/`scopes` as an option which expects a symbol or an array of symbols containing your scopes.
|
149
151
|
|
150
152
|
So lets see how this works:
|
151
153
|
|
@@ -222,6 +224,8 @@ book.favoritable_favorite_cache # => 1
|
|
222
224
|
|
223
225
|
**Note:** These methods are available for every scope you are using.
|
224
226
|
|
227
|
+
The total counts all favorites that were recorded, while the score factors in favorites that were removed. In most use cases the score is the most useful.
|
228
|
+
|
225
229
|
## Configuration
|
226
230
|
|
227
231
|
You can configure acts_as_favoritor by passing a block to `configure`. This can be done in `config/initializers/acts_as_favoritor.rb`:
|
@@ -262,7 +266,7 @@ We warmly welcome everyone who is intersted in contributing. Please reference ou
|
|
262
266
|
|
263
267
|
## Releases
|
264
268
|
|
265
|
-
[Here](https://github.com/jonhue/acts_as_favoritor/releases) you can find details on all past releases. Unreleased breaking changes that are on the current
|
269
|
+
[Here](https://github.com/jonhue/acts_as_favoritor/releases) you can find details on all past releases. Unreleased breaking changes that are on the current `main` can be found [here](CHANGELOG.md).
|
266
270
|
|
267
271
|
acts_as_favoritor follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our [security policy](SECURITY.md).
|
268
272
|
|
@@ -271,6 +275,6 @@ acts_as_favoritor follows Semantic Versioning 2.0 as defined at http://semver.or
|
|
271
275
|
1. Review breaking changes and deprecations in `CHANGELOG.md`.
|
272
276
|
1. Change the gem version in `lib/acts_as_favoritor/version.rb`.
|
273
277
|
1. Reset `CHANGELOG.md`.
|
274
|
-
1. Create a pull request to merge the changes into `
|
275
|
-
1. After the pull request was merged, create a new release listing the breaking changes and commits on `
|
278
|
+
1. Create a pull request to merge the changes into `main`.
|
279
|
+
1. After the pull request was merged, create a new release listing the breaking changes and commits on `main` since the last release.
|
276
280
|
2. The release workflow will publish the gem to RubyGems.
|
@@ -38,13 +38,11 @@ module ActsAsFavoritor
|
|
38
38
|
end
|
39
39
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
40
40
|
|
41
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
42
41
|
def respond_to_missing?(method, include_private = false)
|
43
42
|
super || method.to_s[/(.+)_favoritors/] ||
|
44
43
|
method.to_s[/favoritable_(.+)_score/] ||
|
45
44
|
method.to_s[/favoritable_(.+)_total/]
|
46
45
|
end
|
47
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
48
46
|
|
49
47
|
def favoritors(scope: ActsAsFavoritor.configuration.default_scope,
|
50
48
|
scopes: nil)
|
@@ -12,11 +12,9 @@ module ActsAsFavoritor
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
16
15
|
def respond_to_missing?(method, include_private = false)
|
17
16
|
super || method.to_s[/(.+)_list/]
|
18
17
|
end
|
19
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
20
18
|
|
21
19
|
def for_favoritor(favoritor)
|
22
20
|
where(
|
@@ -38,13 +38,11 @@ module ActsAsFavoritor
|
|
38
38
|
end
|
39
39
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
40
40
|
|
41
|
-
# rubocop:disable Style/OptionalBooleanParameter
|
42
41
|
def respond_to_missing?(method, include_private = false)
|
43
42
|
super || method.to_s[/favorited_(.+)/] ||
|
44
43
|
method.to_s[/favoritor_(.+)_score/] ||
|
45
44
|
method.to_s[/favoritor_(.+)_total/]
|
46
45
|
end
|
47
|
-
# rubocop:enable Style/OptionalBooleanParameter
|
48
46
|
|
49
47
|
def favorite(favoritable,
|
50
48
|
scope: ActsAsFavoritor.configuration.default_scope,
|
@@ -52,10 +50,11 @@ module ActsAsFavoritor
|
|
52
50
|
self.class.build_result_for_scopes(scopes || scope) do |s|
|
53
51
|
return nil if self == favoritable
|
54
52
|
|
55
|
-
inc_cache(favoritable, s) if ActsAsFavoritor.configuration.cache
|
56
|
-
|
57
53
|
favorites.for_favoritable(favoritable).send("#{s}_list")
|
58
|
-
.first_or_create!
|
54
|
+
.first_or_create! do |new_record|
|
55
|
+
inc_cache(favoritable, s) if ActsAsFavoritor.configuration.cache
|
56
|
+
new_record
|
57
|
+
end
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
@@ -64,10 +63,11 @@ module ActsAsFavoritor
|
|
64
63
|
scopes: nil)
|
65
64
|
self.class.build_result_for_scopes(scopes || scope) do |s|
|
66
65
|
favorite_record = get_favorite(favoritable, s)
|
67
|
-
return nil
|
66
|
+
return nil if favorite_record.blank?
|
68
67
|
|
69
|
-
|
70
|
-
|
68
|
+
result = favorite_record.destroy!
|
69
|
+
dec_cache(favoritable, s) if ActsAsFavoritor.configuration.cache && result.destroyed?
|
70
|
+
result
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module ActsAsFavoritor
|
4
4
|
module FavoritorLib
|
5
|
-
def build_result_for_scopes(scopes)
|
5
|
+
def build_result_for_scopes(scopes, &block)
|
6
6
|
return yield(scopes) unless scopes.is_a?(Array)
|
7
7
|
return if scopes.empty?
|
8
8
|
|
9
|
-
sanitized_scopes(scopes).
|
9
|
+
sanitized_scopes(scopes).index_with(&block)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -18,6 +18,10 @@ class ActsAsFavoritorMigration < ActiveRecord::Migration<%= migration_version %>
|
|
18
18
|
add_index :favorites,
|
19
19
|
['favoritable_id', 'favoritable_type'],
|
20
20
|
name: 'fk_favoritables'
|
21
|
+
add_index :favorites,
|
22
|
+
['favoritable_type', 'favoritable_id', 'favoritor_type',
|
23
|
+
'favoritor_id', 'scope'],
|
24
|
+
name: 'uniq_favorites__and_favoritables', unique: true
|
21
25
|
end
|
22
26
|
|
23
27
|
def self.down
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_favoritor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rubocop-rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +142,7 @@ description: acts_as_favoritor is a Rubygem to allow any ActiveRecord model to a
|
|
128
142
|
and whatever else you can imagine through a single relationship. This is accomplished
|
129
143
|
by a double polymorphic relationship on the Favorite model. There is also built
|
130
144
|
in support for blocking/un-blocking favorite records as well as caching.
|
131
|
-
email:
|
145
|
+
email: jonas.huebotter@gmail.com
|
132
146
|
executables: []
|
133
147
|
extensions: []
|
134
148
|
extra_rdoc_files: []
|
@@ -159,14 +173,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
173
|
requirements:
|
160
174
|
- - ">="
|
161
175
|
- !ruby/object:Gem::Version
|
162
|
-
version: '2.
|
176
|
+
version: '2.7'
|
163
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
178
|
requirements:
|
165
179
|
- - ">="
|
166
180
|
- !ruby/object:Gem::Version
|
167
181
|
version: '0'
|
168
182
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.3.7
|
170
184
|
signing_key:
|
171
185
|
specification_version: 4
|
172
186
|
summary: A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord
|