acts_as_favoritor 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +0 -0
- data/README.md +18 -57
- data/lib/acts_as_favoritor.rb +8 -8
- data/lib/acts_as_favoritor/configuration.rb +22 -23
- data/lib/acts_as_favoritor/favoritable.rb +365 -292
- data/lib/acts_as_favoritor/favorite_scopes.rb +66 -59
- data/lib/acts_as_favoritor/favoritor.rb +551 -425
- data/lib/acts_as_favoritor/favoritor_lib.rb +39 -49
- data/lib/acts_as_favoritor/railtie.rb +9 -9
- data/lib/acts_as_favoritor/version.rb +3 -3
- data/lib/generators/acts_as_favoritor_generator.rb +29 -29
- data/lib/generators/templates/initializer.rb +9 -9
- data/lib/generators/templates/migration.rb.erb +16 -14
- data/lib/generators/templates/model.rb +9 -9
- metadata +35 -40
- data/CHANGELOG.md +0 -95
- data/lib/generators/templates/README.md +0 -1
@@ -1,57 +1,47 @@
|
|
1
|
-
|
2
|
-
module FavoritorLib
|
3
|
-
|
4
|
-
private
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
3
|
+
module ActsAsFavoritor
|
4
|
+
module FavoritorLib
|
5
|
+
private
|
7
6
|
|
8
|
-
|
9
|
-
def parent_class_name obj
|
10
|
-
unless parent_classes.include? obj.class.superclass
|
11
|
-
return obj.class.base_class.name
|
12
|
-
end
|
13
|
-
obj.class.name
|
14
|
-
end
|
7
|
+
DEFAULT_PARENTS = [ApplicationRecord, ActiveRecord::Base].freeze
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if options.has_key? :joins
|
24
|
-
scope = scope.joins options[:joins]
|
25
|
-
end
|
26
|
-
if options.has_key? :where
|
27
|
-
scope = scope.where options[:where]
|
28
|
-
end
|
29
|
-
if options.has_key? :order
|
30
|
-
scope = scope.order options[:order]
|
31
|
-
end
|
32
|
-
scope
|
33
|
-
end
|
9
|
+
# Retrieves the parent class name if using STI.
|
10
|
+
def parent_class_name(obj)
|
11
|
+
unless parent_classes.include? obj.class.superclass
|
12
|
+
return obj.class.base_class.name
|
13
|
+
end
|
14
|
+
obj.class.name
|
15
|
+
end
|
34
16
|
|
35
|
-
|
36
|
-
|
37
|
-
|
17
|
+
def apply_options_to_scope(scope, options = {})
|
18
|
+
scope = scope.limit(options[:limit]) if options.key?(:limit)
|
19
|
+
scope = scope.includes(options[:includes]) if options.key?(:includes)
|
20
|
+
scope = scope.joins(options[:joins]) if options.key?(:joins)
|
21
|
+
scope = scope.where(options[:where]) if options.key?(:where)
|
22
|
+
scope = scope.order(options[:order]) if options.key?(:order)
|
23
|
+
scope
|
24
|
+
end
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
options[:multiple_scopes] = true
|
43
|
-
else
|
44
|
-
options[:multiple_scopes] = false
|
45
|
-
options[:scope] = options[:scope][0]
|
46
|
-
end
|
47
|
-
if options.has_key? :parameter
|
48
|
-
parameter = options[:parameter]
|
49
|
-
options.delete :parameter
|
50
|
-
send method, parameter, options
|
51
|
-
else
|
52
|
-
send method, options
|
53
|
-
end
|
54
|
-
end
|
26
|
+
def parent_classes
|
27
|
+
DEFAULT_PARENTS
|
28
|
+
end
|
55
29
|
|
30
|
+
def validate_scopes(method, options = {})
|
31
|
+
options[:scope] ||= [ActsAsFavoritor.configuration.default_scope]
|
32
|
+
if options[:scope].size > 1
|
33
|
+
options[:multiple_scopes] = true
|
34
|
+
else
|
35
|
+
options[:multiple_scopes] = false
|
36
|
+
options[:scope] = options[:scope][0]
|
37
|
+
end
|
38
|
+
if options.key? :parameter
|
39
|
+
parameter = options[:parameter]
|
40
|
+
options.delete :parameter
|
41
|
+
send(method, parameter, options)
|
42
|
+
else
|
43
|
+
send(method, options)
|
44
|
+
end
|
56
45
|
end
|
46
|
+
end
|
57
47
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails/railtie'
|
2
4
|
|
3
5
|
module ActsAsFavoritor
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer 'acts_as_favoritor.active_record' do
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
include ActsAsFavoritor::Favoritor
|
10
|
+
include ActsAsFavoritor::Favoritable
|
11
|
+
end
|
13
12
|
end
|
13
|
+
end
|
14
14
|
end
|
@@ -1,43 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails/generators'
|
2
4
|
require 'rails/generators/migration'
|
3
5
|
|
4
6
|
class ActsAsFavoritorGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
source_root File.join File.dirname(__FILE__), 'templates'
|
9
|
-
desc 'Install acts_as_favoritor'
|
10
|
-
|
11
|
-
def self.next_migration_number dirname
|
12
|
-
if ActiveRecord::Base.timestamped_migrations
|
13
|
-
Time.now.utc.strftime '%Y%m%d%H%M%S'
|
14
|
-
else
|
15
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
-
end
|
17
|
-
end
|
9
|
+
source_root(File.join(File.dirname(__FILE__), 'templates'))
|
10
|
+
desc 'Install acts_as_favoritor'
|
18
11
|
|
19
|
-
|
20
|
-
|
12
|
+
def self.next_migration_number(dirname)
|
13
|
+
if ActiveRecord::Base.timestamped_migrations
|
14
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
15
|
+
else
|
16
|
+
format('%.3d', current_migration_number(dirname) + 1)
|
21
17
|
end
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
def create_initializer
|
21
|
+
template 'initializer.rb', 'config/initializers/acts_as_favoritor.rb'
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def create_migration_file
|
25
|
+
migration_template(
|
26
|
+
'migration.rb.erb',
|
27
|
+
'db/migrate/acts_as_favoritor_migration.rb',
|
28
|
+
migration_version: migration_version
|
29
|
+
)
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def create_model
|
33
|
+
template 'model.rb', 'app/models/favorite.rb'
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
+
private
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
40
|
-
end
|
41
|
-
end
|
38
|
+
def migration_version
|
39
|
+
return unless Rails.version >= '5.0.0'
|
42
40
|
|
41
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
42
|
+
end
|
43
43
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ActsAsFavoritor.configure do |config|
|
4
|
+
# Specify your default scope. Learn more about scopes here: https://github.com/jonhue/acts_as_favoritor#scopes
|
5
|
+
# config.default_scope = 'favorite'
|
6
|
+
|
7
|
+
# Enable caching. Learn more about caching here: https://github.com/jonhue/acts_as_favoritor#caching
|
8
|
+
# config.cache = false
|
9
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
def self.up
|
3
|
-
create_table :favorites, force: true do |t|
|
4
|
-
t.references :favoritable, polymorphic: true, null: false
|
5
|
-
t.references :favoritor, polymorphic: true, null: false
|
6
|
-
t.string :scope, default: ActsAsFavoritor.configuration.default_scope, null: false, index: true
|
7
|
-
t.boolean :blocked, default: false, null: false, index: true
|
8
|
-
t.timestamps
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
10
2
|
|
11
|
-
|
12
|
-
|
3
|
+
class ActsAsFavoritorMigration < ActiveRecord::Migration<%= migration_version %>
|
4
|
+
def self.up
|
5
|
+
create_table :favorites, force: true do |t|
|
6
|
+
t.references :favoritable, polymorphic: true, null: false
|
7
|
+
t.references :favoritor, polymorphic: true, null: false
|
8
|
+
t.string :scope, default: ActsAsFavoritor.configuration.default_scope, null: false, index: true
|
9
|
+
t.boolean :blocked, default: false, null: false, index: true
|
10
|
+
t.timestamps
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
add_index :favorites, ['favoritor_id', 'favoritor_type'], name: 'fk_favorites'
|
14
|
+
add_index :favorites, ['favoritable_id', 'favoritable_type'], name: 'fk_favoritables'
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :favorites
|
19
|
+
end
|
18
20
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
extend ActsAsFavoritor::FavoritorLib
|
4
|
-
extend ActsAsFavoritor::FavoriteScopes
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
3
|
+
class Favorite < ActiveRecord::Base
|
4
|
+
extend ActsAsFavoritor::FavoritorLib
|
5
|
+
extend ActsAsFavoritor::FavoriteScopes
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
belongs_to :favoritable, polymorphic: true
|
8
|
+
belongs_to :favoritor, polymorphic: true
|
12
9
|
|
10
|
+
def block!
|
11
|
+
update(blocked: true)
|
12
|
+
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,125 +1,124 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_favoritor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.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: 2018-
|
11
|
+
date: 2018-07-25 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.
|
19
|
+
version: '5.2'
|
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.
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: factory_bot
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '5.2'
|
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: '
|
54
|
+
version: '5.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: shoulda
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: shoulda_create
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: sqlite3
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
description: acts_as_favoritor is a Rubygem to allow any ActiveRecord model to associate
|
112
112
|
any other model including the option for multiple relationships per association
|
113
113
|
with scopes. You are able to differentiate followers, favorites, watchers, votes
|
114
114
|
and whatever else you can imagine through a single relationship. This is accomplished
|
115
115
|
by a double polymorphic relationship on the Favorite model. There is also built
|
116
116
|
in support for blocking/un-blocking favorite records as well as caching.
|
117
|
-
email:
|
117
|
+
email: me@jonhue.me
|
118
118
|
executables: []
|
119
119
|
extensions: []
|
120
120
|
extra_rdoc_files: []
|
121
121
|
files:
|
122
|
-
- CHANGELOG.md
|
123
122
|
- LICENSE
|
124
123
|
- README.md
|
125
124
|
- lib/acts_as_favoritor.rb
|
@@ -131,7 +130,6 @@ files:
|
|
131
130
|
- lib/acts_as_favoritor/railtie.rb
|
132
131
|
- lib/acts_as_favoritor/version.rb
|
133
132
|
- lib/generators/acts_as_favoritor_generator.rb
|
134
|
-
- lib/generators/templates/README.md
|
135
133
|
- lib/generators/templates/initializer.rb
|
136
134
|
- lib/generators/templates/migration.rb.erb
|
137
135
|
- lib/generators/templates/model.rb
|
@@ -139,10 +137,7 @@ homepage: https://github.com/jonhue/acts_as_favoritor
|
|
139
137
|
licenses:
|
140
138
|
- MIT
|
141
139
|
metadata: {}
|
142
|
-
post_install_message:
|
143
|
-
**Thank you for installing acts_as_favoritor!**
|
144
|
-
Get started by running `rails g acts_as_favoritor`.
|
145
|
-
Learn more at https://github.com/jonhue/acts_as_favoritor.
|
140
|
+
post_install_message:
|
146
141
|
rdoc_options: []
|
147
142
|
require_paths:
|
148
143
|
- lib
|
@@ -158,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
153
|
version: '0'
|
159
154
|
requirements: []
|
160
155
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.7.
|
156
|
+
rubygems_version: 2.7.6
|
162
157
|
signing_key:
|
163
158
|
specification_version: 4
|
164
159
|
summary: A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord
|