acts_as_favoritor 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/INSTALL.md +3 -0
- data/README.md +2 -1
- data/acts_as_favoritor.gemspec +14 -14
- data/lib/acts_as_favoritor/favoritable.rb +11 -11
- data/lib/acts_as_favoritor/favoritor.rb +14 -14
- data/lib/acts_as_favoritor/favoritor_lib.rb +2 -2
- data/lib/acts_as_favoritor/version.rb +1 -1
- data/lib/generators/acts_as_favoritor_generator.rb +1 -2
- data/lib/generators/templates/migration.rb.erb +1 -1
- metadata +16 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f246b9765c928b7e27017c947fe06672eaab987a
|
4
|
+
data.tar.gz: eaafbbd3186d17359c8f33cb6a42794b26e8538f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cacb372f0b3b72bf5040721884bf3a5664dd9c26af954451a592bc6b99a58c0f8c5985aa70b5840720fbd0c27e74e22d2f0da449d150df50005d624a1c8d93e
|
7
|
+
data.tar.gz: cb09807bfa527da8586c7a6a3c5f2bc8c1ed1fd39aa08e946fe57b92825387d382f56e8a27e621af87239fd9a86ad3f117d5e4dfbf2268863c2175c2245140cb
|
data/CHANGELOG.md
CHANGED
data/INSTALL.md
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# `acts_as_favoritor` - Add Favorites to
|
1
|
+
# `acts_as_favoritor` - Add Favorites to your Rails app
|
2
2
|
|
3
3
|
<img src="https://travis-ci.org/slooob/acts_as_favoritor.svg?branch=master" />
|
4
4
|
|
@@ -314,6 +314,7 @@ Test coverage can be calculated using SimpleCov. Make sure you have the [simplec
|
|
314
314
|
## To Do
|
315
315
|
|
316
316
|
* Adding magic methods for scopes, e.g.: `user.follow second_user` instead of `user.favorite second_user, scope: [:follow]`
|
317
|
+
* Allow for caching of counters in the database table of `acts_as_favoritable`.
|
317
318
|
|
318
319
|
---
|
319
320
|
|
data/acts_as_favoritor.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'acts_as_favoritor/version'
|
2
|
+
require File.expand_path(File.join('..', 'lib', 'acts_as_favoritor', 'version'), __FILE__)
|
4
3
|
|
5
4
|
Gem::Specification.new do |gem|
|
6
|
-
gem.name
|
7
|
-
gem.version
|
8
|
-
gem.
|
9
|
-
gem.
|
10
|
-
gem.
|
11
|
-
gem.
|
12
|
-
gem.
|
13
|
-
gem.
|
5
|
+
gem.name = 'acts_as_favoritor'
|
6
|
+
gem.version = ActsAsFavoritor::VERSION
|
7
|
+
gem.platform = Gem::Platform::RUBY
|
8
|
+
gem.summary = 'A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord models'
|
9
|
+
gem.description = 'acts_as_favoritor is a Rubygem to allow any ActiveRecord model to associate any other model including the option for multiple relationships per association with scopes. 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.'
|
10
|
+
gem.authors = ['Jonas Hübotter']
|
11
|
+
gem.email = 'developer@slooob.com'
|
12
|
+
gem.homepage = 'https://github.com/slooob/acts_as_favoritor'
|
13
|
+
gem.license = 'MIT'
|
14
14
|
|
15
|
-
gem.files
|
16
|
-
gem.
|
17
|
-
|
18
|
-
gem.
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.post_install_message = IO.read('INSTALL.md')
|
19
19
|
|
20
20
|
gem.required_ruby_version = '>= 2.3'
|
21
21
|
|
@@ -136,13 +136,13 @@ module ActsAsFavoritor #:nodoc:
|
|
136
136
|
elsif options[:multiple_scopes]
|
137
137
|
results = {}
|
138
138
|
options[:scope].each do |scope|
|
139
|
-
favoritors_scope = favoritors_scoped(scope: scope).unblocked
|
139
|
+
favoritors_scope = favoritors_scoped(scope: scope, multiple_scopes: false).unblocked
|
140
140
|
favoritors_scope = apply_options_to_scope favoritors_scope, options
|
141
141
|
results[scope] = favoritors_scope.to_a.collect{ |f| f.favoritor }
|
142
142
|
end
|
143
143
|
return results
|
144
144
|
else
|
145
|
-
favoritors_scope = favoritors_scoped(scope: options[:scope]).unblocked
|
145
|
+
favoritors_scope = favoritors_scoped(scope: options[:scope], multiple_scopes: false).unblocked
|
146
146
|
favoritors_scope = apply_options_to_scope favoritors_scope, options
|
147
147
|
return favoritors_scope.to_a.collect{ |f| f.favoritor }
|
148
148
|
end
|
@@ -154,13 +154,13 @@ module ActsAsFavoritor #:nodoc:
|
|
154
154
|
elsif options[:multiple_scopes]
|
155
155
|
results = {}
|
156
156
|
options[:scope].each do |scope|
|
157
|
-
blocked_favoritors_scope = favoritors_scoped(scope: scope).blocked
|
157
|
+
blocked_favoritors_scope = favoritors_scoped(scope: scope, multiple_scopes: false).blocked
|
158
158
|
blocked_favoritors_scope = apply_options_to_scope blocked_favoritors_scope, options
|
159
159
|
results[scope] = blocked_favoritors_scope.to_a.collect{ |f| f.favoritor }
|
160
160
|
end
|
161
161
|
return results
|
162
162
|
else
|
163
|
-
blocked_favoritors_scope = favoritors_scoped(scope: options[:scope]).blocked
|
163
|
+
blocked_favoritors_scope = favoritors_scoped(scope: options[:scope], multiple_scopes: false).blocked
|
164
164
|
blocked_favoritors_scope = apply_options_to_scope blocked_favoritors_scope, options
|
165
165
|
return blocked_favoritors_scope.to_a.collect{ |f| f.favoritor }
|
166
166
|
end
|
@@ -237,11 +237,11 @@ module ActsAsFavoritor #:nodoc:
|
|
237
237
|
elsif options[:multiple_scopes]
|
238
238
|
results = {}
|
239
239
|
options[:scope].each do |scope|
|
240
|
-
results[scope] = get_favorite_for(favoritor, scope: scope) ? block_existing_favorite(favoritor, scope: scope) : block_future_favorite(favoritor, scope: scope)
|
240
|
+
results[scope] = get_favorite_for(favoritor, scope: scope, multiple_scopes: false) ? block_existing_favorite(favoritor, scope: scope, multiple_scopes: false) : block_future_favorite(favoritor, scope: scope, multiple_scopes: false)
|
241
241
|
end
|
242
242
|
return results
|
243
243
|
else
|
244
|
-
return get_favorite_for(favoritor, scope: options[:scope]) ? block_existing_favorite(favoritor, scope: options[:scope]) : block_future_favorite(favoritor, scope: options[:scope])
|
244
|
+
return get_favorite_for(favoritor, scope: options[:scope], multiple_scopes: false) ? block_existing_favorite(favoritor, scope: options[:scope], multiple_scopes: false) : block_future_favorite(favoritor, scope: options[:scope], multiple_scopes: false)
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
@@ -252,16 +252,16 @@ module ActsAsFavoritor #:nodoc:
|
|
252
252
|
elsif options[:multiple_scopes]
|
253
253
|
results = {}
|
254
254
|
options[:scope].each do |scope|
|
255
|
-
results[scope] = get_favorite_for(favoritor, scope: scope)&.update_attribute :blocked, false
|
255
|
+
results[scope] = get_favorite_for(favoritor, scope: scope, multiple_scopes: false)&.update_attribute :blocked, false
|
256
256
|
end
|
257
257
|
return results
|
258
258
|
else
|
259
|
-
return get_favorite_for(favoritor, scope: options[:scope])&.update_attribute :blocked, false
|
259
|
+
return get_favorite_for(favoritor, scope: options[:scope], multiple_scopes: false)&.update_attribute :blocked, false
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
263
|
def get_favorite_for favoritor, options = {}
|
264
|
-
if options.has_key?(:multiple_scopes) == false
|
264
|
+
if options.has_key?(:multiple_scopes) == false &&
|
265
265
|
options[:parameter] = favoritor
|
266
266
|
validate_scopes __method__, options
|
267
267
|
elsif options[:multiple_scopes]
|
@@ -299,11 +299,11 @@ module ActsAsFavoritor #:nodoc:
|
|
299
299
|
elsif options[:multiple_scopes]
|
300
300
|
results = {}
|
301
301
|
options[:scope].each do |scope|
|
302
|
-
results[scope] = get_favorite_for(favoritor, scope: scope).block!
|
302
|
+
results[scope] = get_favorite_for(favoritor, scope: scope, multiple_scopes: false).block!
|
303
303
|
end
|
304
304
|
return results
|
305
305
|
else
|
306
|
-
return get_favorite_for(favoritor, scope: options[:scope]).block!
|
306
|
+
return get_favorite_for(favoritor, scope: options[:scope], multiple_scopes: false).block!
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
@@ -123,13 +123,13 @@ module ActsAsFavoritor #:nodoc:
|
|
123
123
|
elsif options[:multiple_scopes]
|
124
124
|
results = {}
|
125
125
|
options[:scope].each do |scope|
|
126
|
-
if favorite = get_favorite(favoritable, scope: scope)
|
126
|
+
if favorite = get_favorite(favoritable, scope: scope, multiple_scopes: false)
|
127
127
|
results[scope] = favorite.destroy
|
128
128
|
end
|
129
129
|
end
|
130
130
|
return results
|
131
131
|
else
|
132
|
-
if favorite = get_favorite(favoritable, scope: options[:scope])
|
132
|
+
if favorite = get_favorite(favoritable, scope: options[:scope], multiple_scopes: false)
|
133
133
|
return favorite.destroy
|
134
134
|
end
|
135
135
|
end
|
@@ -158,12 +158,12 @@ module ActsAsFavoritor #:nodoc:
|
|
158
158
|
elsif options[:multiple_scopes]
|
159
159
|
results = {}
|
160
160
|
options[:scope].each do |scope|
|
161
|
-
favorites_scope = favorites_scoped(scope: scope).for_favoritable_type favoritable_type
|
161
|
+
favorites_scope = favorites_scoped(scope: scope, multiple_scopes: false).for_favoritable_type favoritable_type
|
162
162
|
results[scope] = favorites_scope = apply_options_to_scope favorites_scope, options
|
163
163
|
end
|
164
164
|
return results
|
165
165
|
else
|
166
|
-
favorites_scope = favorites_scoped(scope: options[:scope]).for_favoritable_type favoritable_type
|
166
|
+
favorites_scope = favorites_scoped(scope: options[:scope], multiple_scopes: false).for_favoritable_type favoritable_type
|
167
167
|
return favorites_scope = apply_options_to_scope(favorites_scope, options)
|
168
168
|
end
|
169
169
|
end
|
@@ -175,12 +175,12 @@ module ActsAsFavoritor #:nodoc:
|
|
175
175
|
elsif options[:multiple_scopes]
|
176
176
|
results = {}
|
177
177
|
options[:scope].each do |scope|
|
178
|
-
favorites_scope = favorites_scoped scope: scope
|
178
|
+
favorites_scope = favorites_scoped scope: scope, multiple_scopes: false
|
179
179
|
results[scope] = favorites_scope = apply_options_to_scope favorites_scope, options
|
180
180
|
end
|
181
181
|
return results
|
182
182
|
else
|
183
|
-
favorites_scope = favorites_scoped scope: options[:scope]
|
183
|
+
favorites_scope = favorites_scoped scope: options[:scope], multiple_scopes: false
|
184
184
|
return favorites_scope = apply_options_to_scope(favorites_scope, options)
|
185
185
|
end
|
186
186
|
end
|
@@ -293,13 +293,13 @@ module ActsAsFavoritor #:nodoc:
|
|
293
293
|
elsif options[:multiple_scopes]
|
294
294
|
results = {}
|
295
295
|
options[:scope].each do |scope|
|
296
|
-
blocked_favoritors_scope = favoritables_scoped(scope: scope).blocked
|
296
|
+
blocked_favoritors_scope = favoritables_scoped(scope: scope, multiple_scopes: false).blocked
|
297
297
|
blocked_favoritors_scope = apply_options_to_scope blocked_favoritors_scope, options
|
298
298
|
results[scope] = blocked_favoritors_scope.to_a.collect{ |f| f.favoritable }
|
299
299
|
end
|
300
300
|
return results
|
301
301
|
else
|
302
|
-
blocked_favoritors_scope = favoritors_scoped(scope: options[:scope]).blocked
|
302
|
+
blocked_favoritors_scope = favoritors_scoped(scope: options[:scope], multiple_scopes: false).blocked
|
303
303
|
blocked_favoritors_scope = apply_options_to_scope blocked_favoritors_scope, options
|
304
304
|
return blocked_favoritors_scope.to_a.collect{ |f| f.favoritable }
|
305
305
|
end
|
@@ -312,11 +312,11 @@ module ActsAsFavoritor #:nodoc:
|
|
312
312
|
elsif options[:multiple_scopes]
|
313
313
|
results = {}
|
314
314
|
options[:scope].each do |scope|
|
315
|
-
results[scope] = get_favorite(favoritable, scope: scope) ? block_existing_favorite(favoritable, scope: scope) : block_future_favorite(favoritable, scope: scope)
|
315
|
+
results[scope] = get_favorite(favoritable, scope: scope, multiple_scopes: false) ? block_existing_favorite(favoritable, scope: scope, multiple_scopes: false) : block_future_favorite(favoritable, scope: scope, multiple_scopes: false)
|
316
316
|
end
|
317
317
|
return results
|
318
318
|
else
|
319
|
-
return get_favorite(favoritable, scope: options[:scope]) ? block_existing_favorite(favoritable, scope: options[:scope]) : block_future_favorite(favoritable, scope: options[:scope])
|
319
|
+
return get_favorite(favoritable, scope: options[:scope], multiple_scopes: false) ? block_existing_favorite(favoritable, scope: options[:scope], multiple_scopes: false) : block_future_favorite(favoritable, scope: options[:scope], multiple_scopes: false)
|
320
320
|
end
|
321
321
|
end
|
322
322
|
|
@@ -327,11 +327,11 @@ module ActsAsFavoritor #:nodoc:
|
|
327
327
|
elsif options[:multiple_scopes]
|
328
328
|
results = {}
|
329
329
|
options[:scope].each do |scope|
|
330
|
-
results[scope] = get_favorite(favoritable, scope: scope)&.update_attribute :blocked, false
|
330
|
+
results[scope] = get_favorite(favoritable, scope: scope, multiple_scopes: false)&.update_attribute :blocked, false
|
331
331
|
end
|
332
332
|
return results
|
333
333
|
else
|
334
|
-
return get_favorite(favoritable, scope: options[:scope])&.update_attribute :blocked, false
|
334
|
+
return get_favorite(favoritable, scope: options[:scope], multiple_scopes: false)&.update_attribute :blocked, false
|
335
335
|
end
|
336
336
|
end
|
337
337
|
|
@@ -373,11 +373,11 @@ module ActsAsFavoritor #:nodoc:
|
|
373
373
|
elsif options[:multiple_scopes]
|
374
374
|
results = {}
|
375
375
|
options[:scope].each do |scope|
|
376
|
-
results[scope] = get_favorite(favoritable, scope: scope).block!
|
376
|
+
results[scope] = get_favorite(favoritable, scope: scope, multiple_scopes: false).block!
|
377
377
|
end
|
378
378
|
return results
|
379
379
|
else
|
380
|
-
return get_favorite(favoritable, scope: options[:scope]).block!
|
380
|
+
return get_favorite(favoritable, scope: options[:scope], multiple_scopes: false).block!
|
381
381
|
end
|
382
382
|
end
|
383
383
|
|
@@ -39,9 +39,9 @@ module ActsAsFavoritor
|
|
39
39
|
def validate_scopes method, options = {}
|
40
40
|
options[:scope] = options[:scope] || [ActsAsFavoritor.default_scope]
|
41
41
|
if options[:scope].size > 1
|
42
|
-
options[:multiple_scopes] =
|
42
|
+
options[:multiple_scopes] = true
|
43
43
|
else
|
44
|
-
options[:multiple_scopes] =
|
44
|
+
options[:multiple_scopes] = false
|
45
45
|
options[:scope] = options[:scope][0]
|
46
46
|
end
|
47
47
|
if options.has_key? :parameter
|
@@ -19,8 +19,7 @@ class ActsAsFavoritorGenerator < Rails::Generators::Base
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_migration_file
|
22
|
-
|
23
|
-
migration_template 'migration.rb.erb', 'db/migrate/acts_as_favoritor_migration.rb'
|
22
|
+
migration_template 'migration.rb.erb', 'db/migrate/acts_as_favoritor_migration.rb', migration_version: migration_version
|
24
23
|
end
|
25
24
|
|
26
25
|
def create_model
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class ActsAsFavoritorMigration < ActiveRecord::Migration
|
1
|
+
class ActsAsFavoritorMigration < ActiveRecord::Migration<%= migration_version %>
|
2
2
|
def self.up
|
3
3
|
create_table :favorites, force: true do |t|
|
4
4
|
t.references :favoritable, polymorphic: true, null: false
|
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: 1.2.
|
4
|
+
version: 1.2.1
|
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: 2017-08-
|
11
|
+
date: 2017-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,12 +108,13 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.2017'
|
111
|
-
description: acts_as_favoritor is a Rubygem to allow any ActiveRecord model to
|
112
|
-
any other model
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
-
|
111
|
+
description: acts_as_favoritor is a Rubygem to allow any ActiveRecord model to associate
|
112
|
+
any other model including the option for multiple relationships per association
|
113
|
+
with scopes. You are able to differentiate followers, favorites, watchers, votes
|
114
|
+
and whatever else you can imagine through a single relationship. This is accomplished
|
115
|
+
by a double polymorphic relationship on the Favorite model. There is also built
|
116
|
+
in support for blocking/un-blocking favorite records.
|
117
|
+
email: developer@slooob.com
|
117
118
|
executables: []
|
118
119
|
extensions: []
|
119
120
|
extra_rdoc_files: []
|
@@ -127,6 +128,7 @@ files:
|
|
127
128
|
- CONTRIBUTING.md
|
128
129
|
- DEPRECATIONS.md
|
129
130
|
- Gemfile
|
131
|
+
- INSTALL.md
|
130
132
|
- LICENSE
|
131
133
|
- README.md
|
132
134
|
- Rakefile
|
@@ -177,7 +179,10 @@ homepage: https://github.com/slooob/acts_as_favoritor
|
|
177
179
|
licenses:
|
178
180
|
- MIT
|
179
181
|
metadata: {}
|
180
|
-
post_install_message:
|
182
|
+
post_install_message: |
|
183
|
+
**Thank you for installing acts_as_favoritor!**
|
184
|
+
Get started by running `rails g acts_as_favoritor`.
|
185
|
+
Learn more at https://github.com/slooob/acts_as_favoritor.
|
181
186
|
rdoc_options: []
|
182
187
|
require_paths:
|
183
188
|
- lib
|
@@ -196,5 +201,6 @@ rubyforge_project:
|
|
196
201
|
rubygems_version: 2.6.12
|
197
202
|
signing_key:
|
198
203
|
specification_version: 4
|
199
|
-
summary: A Rubygem to add Favorite, Follow, etc. functionality to ActiveRecord
|
204
|
+
summary: A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord
|
205
|
+
models
|
200
206
|
test_files: []
|