acts_as_favoritor 5.0.1 → 5.0.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: 2554cf505e5a47eb5f24bc1de95fb6287d397259cc70685f4905d99be6164e72
4
- data.tar.gz: ac5749692ac44627c97dfb2797834671f7d3cc368d32e63aac5d2d9a94e4b6b6
3
+ metadata.gz: 64b49c4243f1a6d24e08294de2ee32e19f7b9587ed7f796c2d9d335e6083025a
4
+ data.tar.gz: dc8bc1751b08a7c9837a9a7f1ee1bf4f8059401d11147df8b1c8500fa58151fb
5
5
  SHA512:
6
- metadata.gz: 544dda8f78ced970192a0d523f8c7b4804be135d33afe8635a15eaef3263d5413793d54ca5342fa12636d4a1c893b4d52bb1c160180bb72386c4a144a3280a6b
7
- data.tar.gz: 28fd936df2e6dc96f6b5a2449fc654f40b4307a7d4bed58e5f648652e283af46d3547f1e3ac2245b928400d1391186fae291ff4fc1756438a14afb8c03858abe
6
+ metadata.gz: fb5c2de5270701e94c32b22c703796f309e53db7ad56f55a2171fbe9ebd600f4e7d85084fb5152fbb69539b29ecb0bf9d67f24a6f649ec0818c9089f80c17816
7
+ data.tar.gz: a58a52e5fa812dcc2e985f9be277663be0dc0d4ee3d90e25db362391132e38185e2fe18de6f3a84811b48565afe6caadaad7b38502d998f293ce1d1a2ddecfa2
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:
@@ -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 master can be found [here](CHANGELOG.md).
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 `master`.
275
- 1. After the pull request was merged, create a new release listing the breaking changes and commits on `master` since the last release.
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,10 @@ module ActsAsFavoritor
52
50
  self.class.build_result_for_scopes(scopes || scope) do |s|
53
51
  return nil if self == favoritable
54
52
 
53
+ result = favorites.for_favoritable(favoritable).send("#{s}_list")
54
+ .first_or_create!
55
55
  inc_cache(favoritable, s) if ActsAsFavoritor.configuration.cache
56
-
57
- favorites.for_favoritable(favoritable).send("#{s}_list")
58
- .first_or_create!
56
+ result
59
57
  end
60
58
  end
61
59
 
@@ -66,8 +64,9 @@ module ActsAsFavoritor
66
64
  favorite_record = get_favorite(favoritable, s)
67
65
  return nil unless favorite_record.present?
68
66
 
67
+ result = favorite_record.destroy!
69
68
  dec_cache(favoritable, s) if ActsAsFavoritor.configuration.cache
70
- favorite_record.destroy!
69
+ result
71
70
  end
72
71
  end
73
72
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsFavoritor
4
- VERSION = '5.0.1'
4
+ VERSION = '5.0.2'
5
5
  end
@@ -18,6 +18,9 @@ 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_id', 'favoritor_id', 'favoritable_type'],
23
+ name: 'uniq_favorites__and_favoritables', unique: true
21
24
  end
22
25
 
23
26
  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: 5.0.1
4
+ version: 5.0.2
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: 2020-12-06 00:00:00.000000000 Z
11
+ date: 2021-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -128,7 +128,7 @@ description: acts_as_favoritor is a Rubygem to allow any ActiveRecord model to a
128
128
  and whatever else you can imagine through a single relationship. This is accomplished
129
129
  by a double polymorphic relationship on the Favorite model. There is also built
130
130
  in support for blocking/un-blocking favorite records as well as caching.
131
- email: me@jonhue.me
131
+ email: jonas.huebotter@gmail.com
132
132
  executables: []
133
133
  extensions: []
134
134
  extra_rdoc_files: []
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubygems_version: 3.1.4
169
+ rubygems_version: 3.2.22
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord