acts_as_favoritor 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,57 +1,47 @@
1
- module ActsAsFavoritor
2
- module FavoritorLib
3
-
4
- private
1
+ # frozen_string_literal: true
5
2
 
6
- DEFAULT_PARENTS = [ApplicationRecord, ActiveRecord::Base]
3
+ module ActsAsFavoritor
4
+ module FavoritorLib
5
+ private
7
6
 
8
- # Retrieves the parent class name if using STI.
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
- def apply_options_to_scope scope, options = {}
17
- if options.has_key? :limit
18
- scope = scope.limit options[:limit]
19
- end
20
- if options.has_key? :includes
21
- scope = scope.includes options[:includes]
22
- end
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
- def parent_classes
36
- return DEFAULT_PARENTS
37
- end
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
- def validate_scopes method, options = {}
40
- options[:scope] = options[:scope] || [ActsAsFavoritor.configuration.default_scope]
41
- if options[:scope].size > 1
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
- class Railtie < Rails::Railtie
5
-
6
- initializer 'acts_as_favoritor.active_record' do
7
- ActiveSupport.on_load :active_record do
8
- include ActsAsFavoritor::Favoritor
9
- include ActsAsFavoritor::Favoritable
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,5 +1,5 @@
1
- module ActsAsFavoritor
2
-
3
- VERSION = '2.0.1'
1
+ # frozen_string_literal: true
4
2
 
3
+ module ActsAsFavoritor
4
+ VERSION = '2.1.0'
5
5
  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
- include Rails::Generators::Migration
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
- def create_initializer
20
- template 'initializer.rb', 'config/initializers/acts_as_favoritor.rb'
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
- def create_migration_file
24
- migration_template 'migration.rb.erb', 'db/migrate/acts_as_favoritor_migration.rb', migration_version: migration_version
25
- end
20
+ def create_initializer
21
+ template 'initializer.rb', 'config/initializers/acts_as_favoritor.rb'
22
+ end
26
23
 
27
- def create_model
28
- template 'model.rb', 'app/models/favorite.rb'
29
- end
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
- def show_readme
32
- readme 'README.md'
33
- end
32
+ def create_model
33
+ template 'model.rb', 'app/models/favorite.rb'
34
+ end
34
35
 
35
- private
36
+ private
36
37
 
37
- def migration_version
38
- if Rails.version >= '5.0.0'
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
- ActsAsFavoritor.configure do |config|
2
-
3
- # Specify your default scope. Learn more about scopes here: https://github.com/jonhue/acts_as_favoritor#scopes
4
- # config.default_scope = 'favorite'
5
-
6
- # Enable caching. Learn more about caching here: https://github.com/jonhue/acts_as_favoritor#caching
7
- # config.cache = false
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
- class ActsAsFavoritorMigration < ActiveRecord::Migration<%= migration_version %>
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
- add_index :favorites, ['favoritor_id', 'favoritor_type'], name: 'fk_favorites'
12
- add_index :favorites, ['favoritable_id', 'favoritable_type'], name: 'fk_favoritables'
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
- def self.down
16
- drop_table :favorites
17
- end
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
- class Favorite < ActiveRecord::Base
2
-
3
- extend ActsAsFavoritor::FavoritorLib
4
- extend ActsAsFavoritor::FavoriteScopes
1
+ # frozen_string_literal: true
5
2
 
6
- belongs_to :favoritable, polymorphic: true
7
- belongs_to :favoritor, polymorphic: true
3
+ class Favorite < ActiveRecord::Base
4
+ extend ActsAsFavoritor::FavoritorLib
5
+ extend ActsAsFavoritor::FavoriteScopes
8
6
 
9
- def block!
10
- self.update_attributes blocked: true
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.1
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-01-01 00:00:00.000000000 Z
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.0'
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.0'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
28
+ name: factory_bot
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
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: '1.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: shoulda_create
42
+ name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.0'
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: '0.0'
54
+ version: '5.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: shoulda
56
+ name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.5'
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: '3.5'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: factory_girl
70
+ name: shoulda
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '4.8'
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: '4.8'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rails
84
+ name: shoulda_create
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '5.0'
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: '5.0'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: tzinfo-data
98
+ name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '1.2017'
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: '1.2017'
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: jonas.huebotter@gmail.com
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.4
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