acts_as_favoritor 1.1.2 → 1.1.3

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
  SHA1:
3
- metadata.gz: 76ca5a001f34e1c116394acdf0b14ee10e7af8eb
4
- data.tar.gz: b3fb2d0f0eea52611bb492f7c2c547971dbf24b5
3
+ metadata.gz: 7a2b31e850114a77b2f9784b5240e6f2a7a32256
4
+ data.tar.gz: fb8fea27d053678cf7640837788232af73d6501c
5
5
  SHA512:
6
- metadata.gz: ee98332d5dcbad109d348d4a6ef86fecc6709b8f5d5a497da404adecdc78404f91a389c9e4a60592fb8c542210503ed43471362a39601794ffd8475527f67256
7
- data.tar.gz: 262e4a3890b63782f77b302b3a792bf4bc311199b6fabaacdde5f826fb21a283cb620cb3e840fa17192f8e2f240eb86c02f2c7ab9f845a7e4dc615d73d39072b
6
+ metadata.gz: 4fae80a894f000d0cb63d0d97c43833afdf529c80b599318f9d3c3513b17b5950f5436eb328a82cce2c5830a294fe2bd88a1d0b70ed47d4c64ba0f27fddb7840
7
+ data.tar.gz: a7913c4206d756539eccb8da806f012f1b5213345100266ad08e71bc04cdc0328f3e99ac33e49d485eb2541a52c0615e9fd52eed45426678e503bd8e6fb67cca
@@ -4,6 +4,11 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 1.1.3 - 2017-08-23
8
+
9
+ * bugfixes
10
+ * `fix NoMethodError: undefined method 'each' for <SCOPE>:String`
11
+
7
12
  ### 1.1.2 - 2017-08-23
8
13
 
9
14
  * bugfixes
data/README.md CHANGED
@@ -20,6 +20,7 @@ You are able to differentiate followers, favorites, watchers and whatever else y
20
20
  * [Configuration](#configuration)
21
21
  * [Testing](#testing)
22
22
  * [Test Coverage](#test-coverage)
23
+ * [To Do](#to-do)
23
24
  * [Contributing](#contributing)
24
25
  * [Contributors](#contributors)
25
26
  * [License](#license)
@@ -52,8 +53,9 @@ Now run the generator:
52
53
 
53
54
  $ rails g acts_as_favoritor
54
55
 
55
- You can set your default scope by passing `--scope custom_scope`. Learn more about scopes [here](#scopes)
56
- You can skip the creation of a configuration file by passing `--skip_configuration`. Learn more about configuring `acts_as_favoritor` [here](#configuration)
56
+ You can set your default scope by passing `--scope custom_scope`. Learn more about scopes [here](#scopes).
57
+
58
+ You can skip the creation of a configuration file by passing `--skip_configuration`. Learn more about configuring `acts_as_favoritor` [here](#configuration).
57
59
 
58
60
  To wrap things up, migrate the changes into your database:
59
61
 
@@ -108,13 +110,13 @@ user.favorites_count
108
110
  # Returnes `user`'s favorites that have not been blocked as an array of `Favorite` records.
109
111
  user.all_favorites
110
112
 
111
- # Returns all favorited objects of `user` as an array (unblocked). This can be a collection of different object types, eg: `User`, `Book`.
113
+ # Returns all favorited objects of `user` as an array (unblocked). This can be a collection of different object types, e.g.: `User`, `Book`.
112
114
  user.all_favorited
113
115
 
114
116
  # Returns an array of `Favorite` records where the `favoritable_type` is `Book`.
115
117
  user.favorites_by_type 'Book'
116
118
 
117
- # Returns an array of all favorited objects of `user` where `favoritable_type` is 'Book', this can be a collection of different object types, eg: `User`, `Book`.
119
+ # Returns an array of all favorited objects of `user` where `favoritable_type` is 'Book', this can be a collection of different object types, e.g.: `User`, `Book`.
118
120
  user.favorited_by_type 'Book'
119
121
 
120
122
  # Returns the exact same result as `user.favorited_by_type 'User'`.
@@ -215,6 +217,8 @@ So lets see how this works:
215
217
  ```ruby
216
218
  user.favorite book, scope: [:favorite, :watching]
217
219
  user.remove_favorite book, scope: [:watching]
220
+ second_user = User.find 2
221
+ user.favorite second_user, scope: [:follow]
218
222
  book.block user, scope: [:all] # applies to all scopes
219
223
  ```
220
224
 
@@ -284,6 +288,12 @@ Test coverage can be calculated using SimpleCov. Make sure you have the [simplec
284
288
 
285
289
  ---
286
290
 
291
+ ## To Do
292
+
293
+ * Adding magic methods for scopes, e.g.: `user.follow second_user` instead of `user.favorite second_user, scope: [:follow]`
294
+
295
+ ---
296
+
287
297
  ## Contributing
288
298
 
289
299
  We hope that you will consider contributing to `acts_as_favoritor`. Please read this short overview for some information about how to get started:
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.required_ruby_version = '>= 2.0'
20
+ gem.required_ruby_version = '>= 2.3'
21
21
 
22
22
  gem.add_dependency 'activerecord', '>= 4.0'
23
23
 
@@ -19,7 +19,7 @@ module ActsAsFavoritor #:nodoc:
19
19
  def favoritors_count options = {}
20
20
  if options.has_key?(:multiple_scopes) == false
21
21
  validate_scopes __method__, options
22
- elsif options[:multiple_scopes] == true
22
+ elsif options[:multiple_scopes]
23
23
  results = {}
24
24
  options[:scope].each do |scope|
25
25
  results[scope] = favorited.unblocked.send(scope + '_list').count
@@ -35,7 +35,7 @@ module ActsAsFavoritor #:nodoc:
35
35
  if options.has_key?(:multiple_scopes) == false
36
36
  options[:parameter] = favoritor_type
37
37
  validate_scopes __method__, options
38
- elsif options[:multiple_scopes] == true
38
+ elsif options[:multiple_scopes]
39
39
  results = {}
40
40
  options[:scope].each do |scope|
41
41
  favorites = favoritor_type.constantize.joins(:favorites).where('favorites.blocked': false,
@@ -72,7 +72,7 @@ module ActsAsFavoritor #:nodoc:
72
72
  if options.has_key?(:multiple_scopes) == false
73
73
  options[:parameter] = favoritor_type
74
74
  validate_scopes __method__, options
75
- elsif options[:multiple_scopes] == true
75
+ elsif options[:multiple_scopes]
76
76
  results = {}
77
77
  options[:scope].each do |scope|
78
78
  results[scope] = favorited.unblocked.send(scope + '_list').for_favoritor_type(favoritor_type).count
@@ -104,7 +104,7 @@ module ActsAsFavoritor #:nodoc:
104
104
  def blocked_favoritors_count options = {}
105
105
  if options.has_key?(:multiple_scopes) == false
106
106
  validate_scopes __method__, options
107
- elsif options[:multiple_scopes] == true
107
+ elsif options[:multiple_scopes]
108
108
  results = {}
109
109
  options[:scope].each do |scope|
110
110
  results[scope] = favorited.blocked.send(scope + '_list').count
@@ -119,7 +119,7 @@ module ActsAsFavoritor #:nodoc:
119
119
  def favoritors_scoped options = {}
120
120
  if options.has_key?(:multiple_scopes) == false
121
121
  validate_scopes __method__, options
122
- elsif options[:multiple_scopes] == true
122
+ elsif options[:multiple_scopes]
123
123
  results = {}
124
124
  options[:scope].each do |scope|
125
125
  results[scope] = favorited.send(scope + '_list').includes :favoritor
@@ -133,16 +133,16 @@ module ActsAsFavoritor #:nodoc:
133
133
  def favoritors options = {}
134
134
  if options.has_key?(:multiple_scopes) == false
135
135
  validate_scopes __method__, options
136
- elsif options[:multiple_scopes] == true
136
+ elsif options[:multiple_scopes]
137
137
  results = {}
138
138
  options[:scope].each do |scope|
139
- favoritors_scope = favoritors_scoped(scope).unblocked
139
+ favoritors_scope = favoritors_scoped(scope: scope).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(options[:scope]).unblocked
145
+ favoritors_scope = favoritors_scoped(scope: options[:scope]).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
@@ -151,16 +151,16 @@ module ActsAsFavoritor #:nodoc:
151
151
  def blocks options = {}
152
152
  if options.has_key?(:multiple_scopes) == false
153
153
  validate_scopes __method__, options
154
- elsif options[:multiple_scopes] == true
154
+ elsif options[:multiple_scopes]
155
155
  results = {}
156
156
  options[:scope].each do |scope|
157
- blocked_favoritors_scope = favoritors_scoped(scope).blocked
157
+ blocked_favoritors_scope = favoritors_scoped(scope: scope).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(options[:scope]).blocked
163
+ blocked_favoritors_scope = favoritors_scoped(scope: options[:scope]).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
@@ -172,7 +172,7 @@ module ActsAsFavoritor #:nodoc:
172
172
  if options.has_key?(:multiple_scopes) == false
173
173
  options[:parameter] = favoritor
174
174
  validate_scopes __method__, options
175
- elsif options[:multiple_scopes] == true
175
+ elsif options[:multiple_scopes]
176
176
  results = {}
177
177
  options[:scope].each do |scope|
178
178
  results[scope] = favorited.unblocked.send(scope + '_list').for_favoritor(favoritor).first.present?
@@ -187,7 +187,7 @@ module ActsAsFavoritor #:nodoc:
187
187
  if options.has_key?(:multiple_scopes) == false
188
188
  options[:parameter] = favoritor
189
189
  validate_scopes __method__, options
190
- elsif options[:multiple_scopes] == true
190
+ elsif options[:multiple_scopes]
191
191
  results = {}
192
192
  options[:scope].each do |scope|
193
193
  results[scope] = get_favorite_for(favoritor, scope: scope) ? block_existing_favorite(favoritor, scope: scope) : block_future_favorite(favoritor, scope: scope)
@@ -202,14 +202,14 @@ module ActsAsFavoritor #:nodoc:
202
202
  if options.has_key?(:multiple_scopes) == false
203
203
  options[:parameter] = favoritor
204
204
  validate_scopes __method__, options
205
- elsif options[:multiple_scopes] == true
205
+ elsif options[:multiple_scopes]
206
206
  results = {}
207
207
  options[:scope].each do |scope|
208
- results[scope] = get_favorite_for(favoritor, scope: scope).update_attribute :blocked, false
208
+ results[scope] = get_favorite_for(favoritor, scope: scope)&.update_attribute :blocked, false
209
209
  end
210
210
  return results
211
211
  else
212
- return get_favorite_for(favoritor, scope: options[:scope]).update_attribute :blocked, false
212
+ return get_favorite_for(favoritor, scope: options[:scope])&.update_attribute :blocked, false
213
213
  end
214
214
  end
215
215
 
@@ -217,7 +217,7 @@ module ActsAsFavoritor #:nodoc:
217
217
  if options.has_key?(:multiple_scopes) == false
218
218
  options[:parameter] = favoritor
219
219
  validate_scopes __method__, options
220
- elsif options[:multiple_scopes] == true
220
+ elsif options[:multiple_scopes]
221
221
  results = {}
222
222
  options[:scope].each do |scope|
223
223
  results[scope] = favorited.send(scope + '_list').for_favoritor(favoritor).first
@@ -234,7 +234,7 @@ module ActsAsFavoritor #:nodoc:
234
234
  if options.has_key?(:multiple_scopes) == false
235
235
  options[:parameter] = favoritor
236
236
  validate_scopes __method__, options
237
- elsif options[:multiple_scopes] == true
237
+ elsif options[:multiple_scopes]
238
238
  results = {}
239
239
  options[:scope].each do |scope|
240
240
  results[scope] = Favorite.create favoritable: self, favoritor: favoritor, blocked: true, scope: scope
@@ -249,7 +249,7 @@ module ActsAsFavoritor #:nodoc:
249
249
  if options.has_key?(:multiple_scopes) == false
250
250
  options[:parameter] = favoritor
251
251
  validate_scopes __method__, options
252
- elsif options[:multiple_scopes] == true
252
+ elsif options[:multiple_scopes]
253
253
  results = {}
254
254
  options[:scope].each do |scope|
255
255
  results[scope] = get_favorite_for(favoritor, scope: scope).block!
@@ -20,7 +20,7 @@ module ActsAsFavoritor #:nodoc:
20
20
  if options.has_key?(:multiple_scopes) == false
21
21
  options[:parameter] = favoritable
22
22
  validate_scopes __method__, options
23
- elsif options[:multiple_scopes] == true
23
+ elsif options[:multiple_scopes]
24
24
  results = {}
25
25
  options[:scope].each do |scope|
26
26
  results[scope] = 0 < Favorite.unblocked.send(scope + '_list').for_favoritor(self).for_favoritable(favoritable).count
@@ -35,8 +35,7 @@ module ActsAsFavoritor #:nodoc:
35
35
  def favorites_count options = {}
36
36
  if options.has_key?(:multiple_scopes) == false
37
37
  validate_scopes __method__, options
38
- elsif options[:multiple_scopes] == true
39
- raise options.to_s
38
+ elsif options[:multiple_scopes]
40
39
  results = {}
41
40
  options[:scope].each do |scope|
42
41
  results[scope] = Favorite.unblocked.send(scope + '_list').for_favoritor(self).count
@@ -53,7 +52,7 @@ module ActsAsFavoritor #:nodoc:
53
52
  if options.has_key?(:multiple_scopes) == false
54
53
  options[:parameter] = favoritable
55
54
  validate_scopes __method__, options
56
- elsif options[:multiple_scopes] == true
55
+ elsif options[:multiple_scopes]
57
56
  results = {}
58
57
  options[:scope].each do |scope|
59
58
  if self != favoritable && scope != 'all'
@@ -75,16 +74,16 @@ module ActsAsFavoritor #:nodoc:
75
74
  if options.has_key?(:multiple_scopes) == false
76
75
  options[:parameter] = favoritable
77
76
  validate_scopes __method__, options
78
- elsif options[:multiple_scopes] == true
77
+ elsif options[:multiple_scopes]
79
78
  results = {}
80
79
  options[:scope].each do |scope|
81
- if favorite = get_favorite(favoritable).send(scope + '_list')
80
+ if favorite = get_favorite(favoritable)&.send(scope + '_list')
82
81
  results[scope] = favorite.destroy
83
82
  end
84
83
  end
85
84
  return results
86
85
  else
87
- if favorite = get_favorite(favoritable).send(options[:scope] + '_list')
86
+ if favorite = get_favorite(favoritable)&.send(options[:scope] + '_list')
88
87
  return favorite.destroy
89
88
  end
90
89
  end
@@ -94,7 +93,7 @@ module ActsAsFavoritor #:nodoc:
94
93
  def favorites_scoped options = {}
95
94
  if options.has_key?(:multiple_scopes) == false
96
95
  validate_scopes __method__, options
97
- elsif options[:multiple_scopes] == true
96
+ elsif options[:multiple_scopes]
98
97
  results = {}
99
98
  options[:scope].each do |scope|
100
99
  results[scope] = favorites.unblocked.send(scope + '_list').includes :favoritable
@@ -110,15 +109,15 @@ module ActsAsFavoritor #:nodoc:
110
109
  if options.has_key?(:multiple_scopes) == false
111
110
  options[:parameter] = favoritable_type
112
111
  validate_scopes __method__, options
113
- elsif options[:multiple_scopes] == true
112
+ elsif options[:multiple_scopes]
114
113
  results = {}
115
114
  options[:scope].each do |scope|
116
- favorites_scope = favorites_scoped(scope).for_favoritable_type favoritable_type
115
+ favorites_scope = favorites_scoped(scope: scope).for_favoritable_type favoritable_type
117
116
  results[scope] = favorites_scope = apply_options_to_scope favorites_scope, options
118
117
  end
119
118
  return results
120
119
  else
121
- favorites_scope = favorites_scoped(options[:scope]).for_favoritable_type favoritable_type
120
+ favorites_scope = favorites_scoped(scope: options[:scope]).for_favoritable_type favoritable_type
122
121
  return favorites_scope = apply_options_to_scope(favorites_scope, options)
123
122
  end
124
123
  end
@@ -127,15 +126,15 @@ module ActsAsFavoritor #:nodoc:
127
126
  def all_favorites options = {}
128
127
  if options.has_key?(:multiple_scopes) == false
129
128
  validate_scopes __method__, options
130
- elsif options[:multiple_scopes] == true
129
+ elsif options[:multiple_scopes]
131
130
  results = {}
132
131
  options[:scope].each do |scope|
133
- favorites_scope = favorites_scoped scope
132
+ favorites_scope = favorites_scoped scope: scope
134
133
  results[scope] = favorites_scope = apply_options_to_scope favorites_scope, options
135
134
  end
136
135
  return results
137
136
  else
138
- favorites_scope = favorites_scoped options[:scope]
137
+ favorites_scope = favorites_scoped scope: options[:scope]
139
138
  return favorites_scope = apply_options_to_scope(favorites_scope, options)
140
139
  end
141
140
  end
@@ -150,7 +149,7 @@ module ActsAsFavoritor #:nodoc:
150
149
  if options.has_key?(:multiple_scopes) == false
151
150
  options[:parameter] = favoritable_type
152
151
  validate_scopes __method__, options
153
- elsif options[:multiple_scopes] == true
152
+ elsif options[:multiple_scopes]
154
153
  results = {}
155
154
  options[:scope].each do |scope|
156
155
  favoritables = favoritable_type.constantize.joins(:favorited).where('favorites.blocked': false,
@@ -187,7 +186,7 @@ module ActsAsFavoritor #:nodoc:
187
186
  if options.has_key?(:multiple_scopes) == false
188
187
  options[:parameter] = favoritable_type
189
188
  validate_scopes __method__, options
190
- elsif options[:multiple_scopes] == true
189
+ elsif options[:multiple_scopes]
191
190
  results = {}
192
191
  options[:scope].each do |scope|
193
192
  results[scope] = favorites.unblocked.send(scope + '_list').for_favoritable_type(favoritable_type).count
@@ -221,7 +220,7 @@ module ActsAsFavoritor #:nodoc:
221
220
  if options.has_key?(:multiple_scopes) == false
222
221
  options[:parameter] = favoritable
223
222
  validate_scopes __method__, options
224
- elsif options[:multiple_scopes] == true
223
+ elsif options[:multiple_scopes]
225
224
  results = {}
226
225
  options[:scope].each do |scope|
227
226
  results[scope] = favorites.unblocked.send(scope + '_list').for_favoritable(favoritable).first
@@ -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] = true
42
+ options[:multiple_scopes] = false # ?
43
43
  else
44
- options[:multiple_scopes] = false
44
+ options[:multiple_scopes] = true # ?
45
45
  options[:scope] = options[:scope][0]
46
46
  end
47
47
  if options.has_key? :parameter
@@ -1,5 +1,5 @@
1
1
  module ActsAsFavoritor
2
2
 
3
- VERSION = '1.1.2'
3
+ VERSION = '1.1.3'
4
4
 
5
5
  end
@@ -19,6 +19,7 @@ class ActsAsFavoritorGenerator < Rails::Generators::Base
19
19
  end
20
20
 
21
21
  def create_migration_file
22
+ @rails_version = Rails::VERSION::STRING[0..2].to_f
22
23
  migration_template 'migration.rb.erb', 'db/migrate/acts_as_favoritor_migration.rb'
23
24
  end
24
25
 
@@ -1,4 +1,4 @@
1
- class ActsAsFavoritorMigration < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[Rails::VERSION::STRING[0..2].to_f]<% end %>
1
+ class ActsAsFavoritorMigration < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[<%= @rails_version %>]<% end %>
2
2
  def self.up
3
3
  create_table :favorites, force: true do |t|
4
4
  t.references :favoritable, polymorphic: true, null: false
@@ -234,8 +234,8 @@ class ActsAsFavoritableTest < ActiveSupport::TestCase
234
234
  end
235
235
 
236
236
  should 'return the favoritors for given type' do
237
- assert_equal @sam.favorites_by_type('Band').first.favoritable, @green_day.becomes(Band)
238
- assert_equal @sam.favorites_by_type('Band').second.favoritable, @blink_182.becomes(Band)
237
+ assert_equal @sam.favorites_by_type('Band').first&.favoritable, @green_day.becomes(Band)
238
+ assert_equal @sam.favorites_by_type('Band').second&.favoritable, @blink_182.becomes(Band)
239
239
  assert @green_day.favoritors_by_type('User').include?(@sam)
240
240
  assert @blink_182.favoritors_by_type('User').include?(@sam)
241
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_favoritor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
- version: '2.0'
188
+ version: '2.3'
189
189
  required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="