acts_as_favoritor 1.1.0 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0212cb5d6caa611de18d2d40fdc63d222cb53fbd
4
- data.tar.gz: 80a038d9ede85643ee8ef0f603e80ba6c5f4c621
3
+ metadata.gz: 76ca5a001f34e1c116394acdf0b14ee10e7af8eb
4
+ data.tar.gz: b3fb2d0f0eea52611bb492f7c2c547971dbf24b5
5
5
  SHA512:
6
- metadata.gz: 6bd55853cbcfad24a096d22148f0ad9f8db4da64a8a9c8af89af0436c9debd0de3a24cfe6420fd07a96f9fd85f690c6d37b6dedc3762ad214712477e6f485bfc
7
- data.tar.gz: d34d88eac6378f1a700409ee854a6e2f9c7257a700984cc63ee708fccf753eecdb57bb4a8812afbdacaabaa3b802fc8d3c5fd8f476a72f10a44e2c94fccc548a
6
+ metadata.gz: ee98332d5dcbad109d348d4a6ef86fecc6709b8f5d5a497da404adecdc78404f91a389c9e4a60592fb8c542210503ed43471362a39601794ffd8475527f67256
7
+ data.tar.gz: 262e4a3890b63782f77b302b3a792bf4bc311199b6fabaacdde5f826fb21a283cb620cb3e840fa17192f8e2f240eb86c02f2c7ab9f845a7e4dc615d73d39072b
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ ### unreleased
4
+
5
+ * nothing yet
6
+
7
+ ### 1.1.2 - 2017-08-23
8
+
9
+ * bugfixes
10
+ * migration hotfix
11
+
12
+ ### 1.1.1 - 2017-08-23
13
+
14
+ * notes
15
+ * default scope changed from `favorites` to `favorite`
16
+ * features
17
+ * added configuration
18
+ * enhancements
19
+ * add `scope` generator option
20
+ * add `skip_configuration` generator option
21
+ * index database columns
22
+ * minor bugfixes
23
+
24
+ ### 1.1.0 - 2017-08-23
25
+
26
+ * features
27
+ * add scope functionality
28
+
29
+ ### 1.0.2 - 2017-08-22
30
+
31
+ * enhancements
32
+
33
+ ### 1.0.1 - 2017-08-22
34
+
35
+ * bug fixes
36
+
37
+ ### 1.0.0 - 2017-08-22
38
+
39
+ * initial release
data/README.md CHANGED
@@ -17,6 +17,7 @@ You are able to differentiate followers, favorites, watchers and whatever else y
17
17
  * [`acts_as_favoritable` methods](#acts_as_favoritable-methods)
18
18
  * [`Favorite` model](#favorite-model)
19
19
  * [Scopes](#scopes)
20
+ * [Configuration](#configuration)
20
21
  * [Testing](#testing)
21
22
  * [Test Coverage](#test-coverage)
22
23
  * [Contributing](#contributing)
@@ -51,12 +52,17 @@ Now run the generator:
51
52
 
52
53
  $ rails g acts_as_favoritor
53
54
 
54
- $ rails db:migrate
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)
55
57
 
56
- This will create a Favorite model as well as a migration file.
58
+ To wrap things up, migrate the changes into your database:
59
+
60
+ $ rails db:migrate
57
61
 
58
62
  **Note:** Use `rake db:migrate` instead if you run Rails < 5.
59
63
 
64
+ This will create a Favorite model as well as a migration file.
65
+
60
66
  ## Usage
61
67
 
62
68
  ### Setup
@@ -198,16 +204,16 @@ Favorite.for_favoritable book
198
204
 
199
205
  ### Scopes
200
206
 
201
- Using scopes with `acts_as_favoritor` enables you to Follow, Watch, Favorite, [...] between any of your models. This way you can separate distinct functionalities in your app between user states. For example: A user sees all his favorited books in a dashboard (`'favorites'`), but he only receives notifications for those, he is watching (`'watching'`). Just like YouTube does it.
207
+ Using scopes with `acts_as_favoritor` enables you to Follow, Watch, Favorite, [...] between any of your models. This way you can separate distinct functionalities in your app between user states. For example: A user sees all his favorited books in a dashboard (`'favorite'`), but he only receives notifications for those, he is watching (`'watch'`). Just like YouTube does it.
202
208
 
203
- By default all of your favorites are scoped to `'favorites'`.
209
+ By default all of your favorites are scoped to `'favorite'`.
204
210
 
205
211
  You can create new scopes on the fly. Every single method takes `scope` as an option which expexts an array containing your scopes as strings.
206
212
 
207
213
  So lets see how this works:
208
214
 
209
215
  ```ruby
210
- user.favorite book, scope: [:favorites, :watching]
216
+ user.favorite book, scope: [:favorite, :watching]
211
217
  user.remove_favorite book, scope: [:watching]
212
218
  book.block user, scope: [:all] # applies to all scopes
213
219
  ```
@@ -217,7 +223,7 @@ That's simple!
217
223
  When you call a method which returns something while specifying multiple scopes, the method returns the results in a hash with the scopes as keys:
218
224
 
219
225
  ```ruby
220
- user.favorited? book, scope: [:favorites, :watching] # => { favorites: true, watching: false }
226
+ user.favorited? book, scope: [:favorite, :watching] # => { favorite: true, watching: false }
221
227
  user.favorited? book, scope: [:all] # => true
222
228
  ```
223
229
 
@@ -229,7 +235,7 @@ Favorite.send(my_scope + '_list')
229
235
 
230
236
  ## Examples
231
237
  ### Returns all `Favorite` records where `scope` is `favorites`
232
- Favorite.favorites_list
238
+ Favorite.favorite_list
233
239
  ### Returns all `Favorite` records where `scope` is `watching`
234
240
  Favorite.watching_list
235
241
  ### Very unnecessary, but `all_list` returns literally all `Favorite` records
@@ -238,6 +244,20 @@ Favorite.all_list
238
244
 
239
245
  ---
240
246
 
247
+ ## Configuration
248
+
249
+ The installer creates a yaml config file for you (`config/acts_as_favoritor.yml`). Inside of that file you are able to adopt this gem to your specific needs.
250
+
251
+ When you delete this file, all settings will rollback to their defaults. You can prevent the creation of this configuration file when running the generator by passing the option `--skip_configuration`.
252
+
253
+ Currently supported Settings:
254
+
255
+ **default_scope:** Specify your default scope. Learn more about scopes here: https://github.com/slooob/acts_as_favoritor#scopes
256
+
257
+ If you have an idea for a new setting, propose it by creating a new [issue](https://github.com/slooob/acts_as_favoritor/issues).
258
+
259
+ ---
260
+
241
261
  ## Testing
242
262
 
243
263
  Tests are written with Shoulda on top of `Test::Unit` with Factory Girl being used instead of fixtures. Tests are run using rake.
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.authors = ['Jonas Hübotter']
9
9
  gem.email = ['developer@slooob.com']
10
10
  gem.homepage = 'https://github.com/slooob/acts_as_favoritor'
11
- gem.summary = 'A Rubygem to add Favorite functionality for ActiveRecord models'
11
+ gem.summary = 'A Rubygem to add Favorite, Follow, etc. functionality to ActiveRecord models'
12
12
  gem.description = 'acts_as_favoritor is a Rubygem to allow any ActiveRecord model to favorite any other model. This is accomplished through a double polymorphic relationship on the Favorite model. There is also built in support for blocking/un-blocking favorite records.'
13
13
  gem.license = 'MIT'
14
14
 
@@ -9,4 +9,6 @@ module ActsAsFavoritor
9
9
 
10
10
  require 'acts_as_favoritor/railtie' if defined?(Rails)
11
11
 
12
+ require 'acts_as_favoritor/configuration'
13
+
12
14
  end
@@ -0,0 +1,25 @@
1
+ module ActsAsFavoritor
2
+
3
+ def self.default_scope
4
+ config = get_config
5
+ if config&.key :default_scope
6
+ config[:default_scope]
7
+ else
8
+ 'favorite'
9
+ end
10
+ end
11
+
12
+
13
+ private
14
+
15
+
16
+ def self.get_config
17
+ require 'yaml'
18
+
19
+ begin
20
+ YAML.load_file 'config/acts_as_favoritor.yml'
21
+ rescue Exception
22
+ end
23
+ end
24
+
25
+ end
@@ -1,15 +1,20 @@
1
1
  module ActsAsFavoritor #:nodoc:
2
2
  module FavoriteScopes
3
3
 
4
- # send(scope + '_list') - returns favorite records of scope
5
- Favorite.all.group_by(&:scope).each do |s|
6
- Favorite.send(:define_method, "#{s}_list") do
7
- where scope: s
4
+ # Allows magic names on send(scope + '_list') - returns favorite records of certain scope
5
+ # e.g. favoritors == favoritors.send('favorite_list')
6
+ def method_missing m, *args
7
+ if m.to_s[/(.+)_list/]
8
+ where scope: $1.singularize.classify
9
+ else
10
+ super
8
11
  end
9
12
  end
10
- def favorites_list
11
- where scope: 'favorites'
13
+
14
+ def respond_to? m, include_private = false
15
+ super || m.to_s[/(.+)_list/]
12
16
  end
17
+
13
18
  def all_list
14
19
  all
15
20
  end
@@ -37,7 +37,7 @@ module ActsAsFavoritor
37
37
  end
38
38
 
39
39
  def validate_scopes method, options = {}
40
- options[:scope] = options[:scope] || ['favorites']
40
+ options[:scope] = options[:scope] || ActsAsFavoritor.default_scope
41
41
  if options[:scope].size > 1
42
42
  options[:multiple_scopes] = true
43
43
  else
@@ -1,5 +1,5 @@
1
1
  module ActsAsFavoritor
2
2
 
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.2'
4
4
 
5
5
  end
@@ -5,9 +5,10 @@ class ActsAsFavoritorGenerator < Rails::Generators::Base
5
5
 
6
6
  include Rails::Generators::Migration
7
7
 
8
- def self.source_root
9
- @source_root ||= File.join File.dirname(__FILE__), 'templates'
10
- end
8
+ source_root File.join File.dirname(__FILE__), 'templates'
9
+ desc 'Install acts_as_favoritor'
10
+ class_option :scope, desc: 'Specify your default scope. Learn more about scopes here: https://github.com/slooob/acts_as_favoritor#scopes', type: :string, default: 'favorite', aliases: '-s'
11
+ class_option :skip_configuration, desc: 'Skip the creation of the configuration file. Learn more about configuring acts_as_favoritor here: https://github.com/slooob/acts_as_favoritor#configuration', type: :boolean, default: false
11
12
 
12
13
  def self.next_migration_number dirname
13
14
  if ActiveRecord::Base.timestamped_migrations
@@ -25,6 +26,10 @@ class ActsAsFavoritorGenerator < Rails::Generators::Base
25
26
  template 'model.rb', 'app/models/favorite.rb'
26
27
  end
27
28
 
29
+ def create_configuration
30
+ template 'acts_as_favoritor.yml.erb', 'config/acts_as_favoritor.yml' unless options[:skip_configuration]
31
+ end
32
+
28
33
  def show_readme
29
34
  readme 'README.md'
30
35
  end
@@ -0,0 +1,6 @@
1
+ # ----------
2
+ # ACTS AS FAVORITOR
3
+ # ----------
4
+
5
+ # Specify your default scope. Learn more about scopes here: https://github.com/slooob/acts_as_favoritor#scopes
6
+ default_scope: <%= options[:scope] %>
@@ -3,8 +3,8 @@ class ActsAsFavoritorMigration < ActiveRecord::Migration<% if Rails::VERSION::MA
3
3
  create_table :favorites, force: true do |t|
4
4
  t.references :favoritable, polymorphic: true, null: false
5
5
  t.references :favoritor, polymorphic: true, null: false
6
- t.string :scope, default: 'favorites', null: false
7
- t.boolean :blocked, default: false, null: false
6
+ t.string :scope, default: ActsAsFavoritor.default_scope, null: false, index: true
7
+ t.boolean :blocked, default: false, null: false, index: true
8
8
  t.timestamps
9
9
  end
10
10
 
@@ -5,7 +5,7 @@ ActiveRecord::Schema.define version: 0 do
5
5
  t.string 'favoritable_type', null: false
6
6
  t.integer 'favoritor_id', null: false
7
7
  t.string 'favoritor_type', null: false
8
- t.string :scope, default: 'favorites', null: false
8
+ t.string :scope, default: ActsAsFavoritor.default_scope, null: false
9
9
  t.boolean 'blocked', default: false, null: false
10
10
  t.datetime 'created_at'
11
11
  t.datetime 'updated_at'
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.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
@@ -122,6 +122,7 @@ files:
122
122
  - ".github/pull_request_template.md"
123
123
  - ".gitignore"
124
124
  - ".travis.yml"
125
+ - CHANGELOG.md
125
126
  - CODE_OF_CONDUCT.md
126
127
  - CONTRIBUTING.md
127
128
  - DEPRECATIONS.md
@@ -132,6 +133,7 @@ files:
132
133
  - acts_as_favoritor.gemspec
133
134
  - init.rb
134
135
  - lib/acts_as_favoritor.rb
136
+ - lib/acts_as_favoritor/configuration.rb
135
137
  - lib/acts_as_favoritor/favoritable.rb
136
138
  - lib/acts_as_favoritor/favorite_scopes.rb
137
139
  - lib/acts_as_favoritor/favoritor.rb
@@ -140,6 +142,7 @@ files:
140
142
  - lib/acts_as_favoritor/version.rb
141
143
  - lib/generators/acts_as_favoritor_generator.rb
142
144
  - lib/generators/templates/README.md
145
+ - lib/generators/templates/acts_as_favoritor.yml.erb
143
146
  - lib/generators/templates/migration.rb.erb
144
147
  - lib/generators/templates/model.rb
145
148
  - test/acts_as_favoritable_test.rb
@@ -193,5 +196,5 @@ rubyforge_project:
193
196
  rubygems_version: 2.6.12
194
197
  signing_key:
195
198
  specification_version: 4
196
- summary: A Rubygem to add Favorite functionality for ActiveRecord models
199
+ summary: A Rubygem to add Favorite, Follow, etc. functionality to ActiveRecord models
197
200
  test_files: []