acts_as_favoritor 2.1.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,41 +8,26 @@ module ActsAsFavoritor
8
8
 
9
9
  # Retrieves the parent class name if using STI.
10
10
  def parent_class_name(obj)
11
- unless parent_classes.include? obj.class.superclass
11
+ unless DEFAULT_PARENTS.include? obj.class.superclass
12
12
  return obj.class.base_class.name
13
13
  end
14
14
 
15
15
  obj.class.name
16
16
  end
17
17
 
18
- def apply_options_to_scope(scope, options = {})
19
- scope = scope.limit(options[:limit]) if options.key?(:limit)
20
- scope = scope.includes(options[:includes]) if options.key?(:includes)
21
- scope = scope.joins(options[:joins]) if options.key?(:joins)
22
- scope = scope.where(options[:where]) if options.key?(:where)
23
- scope = scope.order(options[:order]) if options.key?(:order)
24
- scope
25
- end
18
+ def build_result_for_scopes(scopes)
19
+ return if scopes.empty?
20
+
21
+ scopes = sanitized_scopes(scopes)
22
+ result = scopes.map { |scope| [scope, yield(scope)] }.to_h
23
+
24
+ return result[scopes.first] if scopes.size == 1
26
25
 
27
- def parent_classes
28
- DEFAULT_PARENTS
26
+ result
29
27
  end
30
28
 
31
- def validate_scopes(method, options = {})
32
- options[:scope] ||= [ActsAsFavoritor.configuration.default_scope]
33
- if options[:scope].size > 1
34
- options[:multiple_scopes] = true
35
- else
36
- options[:multiple_scopes] = false
37
- options[:scope] = options[:scope][0]
38
- end
39
- if options.key? :parameter
40
- parameter = options[:parameter]
41
- options.delete :parameter
42
- send(method, parameter, options)
43
- else
44
- send(method, options)
45
- end
29
+ def sanitized_scopes(scopes)
30
+ scopes.map(&:to_sym)
46
31
  end
47
32
  end
48
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsFavoritor
4
- VERSION = '2.1.2'
4
+ VERSION = '3.0.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Favorite < ActiveRecord::Base
3
+ class Favorite < ApplicationRecord
4
4
  extend ActsAsFavoritor::FavoritorLib
5
5
  extend ActsAsFavoritor::FavoriteScopes
6
6
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_favoritor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 3.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: 2019-05-03 00:00:00.000000000 Z
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: factory_bot
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,18 +42,18 @@ dependencies:
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.2'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5.2'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
56
+ name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: shoulda
70
+ name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: shoulda_create
84
+ name: rubocop-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="