acts_as_favoritor 1.0.1 → 1.0.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: 51b26144e2f4621c21c2733217190573550f4457
4
- data.tar.gz: 7ac65f0fd1d99f1a22186a975d11031cc79ed047
3
+ metadata.gz: 94041c9376e8e337edf53d7c84397c30b9e2b562
4
+ data.tar.gz: f0d6c7694c0c3c3b218a5a9fc800d63ce29e68ce
5
5
  SHA512:
6
- metadata.gz: bbb04b517631931b8fc8cd4eb091eb43f3a1b09635ca7aecc2d5d0979731177989db605b8114bcf7de871a58ea5ee9744b20b22fc0f00fee74ac4206d5102c13
7
- data.tar.gz: d710797509f89e5bf16936a9f8da7f8d72f47cf0eb635dc229b04b23d9081be374e2a3718db12855c1044cb5bcd13b139baacffa1139fa2176b09d0eb3c29d05
6
+ metadata.gz: aa60c403515beb2407e424220641c8d9ba8f796ee5892863da3c187c93b9e1f1a9bffe11638f487419bc2fac53fd9c79d298c67395989cacd65df144c9508d31
7
+ data.tar.gz: fb30725d86c0c6b3815975fdc33cfc9d9490dcf9cca5191e47b7900d193b227aec7978fb63059596fb782a37cb3e7640b8691a7eee0a5225a0860e6baece42a8
data/.gitignore CHANGED
@@ -4,4 +4,5 @@ rdoc
4
4
  memory
5
5
  *.gem
6
6
  .rvmrc
7
+ Gemfile.lock
7
8
  log
data/.travis.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.3
4
- install: bundle install --without development --deployment --jobs=3 --retry=3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  * nothing yet
4
4
 
5
+ ### 1.0.2 - 2017-08-22
6
+
7
+ * minor improvements
8
+
5
9
  ### 1.0.1 - 2017-08-22
6
10
 
7
11
  * bug fixes
data/README.md CHANGED
@@ -1,14 +1,28 @@
1
- # acts_as_favoritor - Add Favorites to you Rails app
1
+ # `acts_as_favoritor` - Add Favorites to you Rails app
2
2
 
3
3
  <img src="https://travis-ci.org/slooob/acts_as_favoritor.svg?branch=master" />
4
4
 
5
- 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.
5
+ `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.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [Setup](#setup)
14
+ * [`acts_as_favoritor` methods](#acts_as_favoritor-methods)
15
+ * [`acts_as_favoritable` methods](#acts_as_favoritable-methods)
16
+ * [`Favorite` model](#favorite-model)
17
+ * [To Do List](#to-do-list)
18
+ * [Contributors](#contributors)
19
+ * [License](#license)
6
20
 
7
21
  ---
8
22
 
9
23
  ## Installation
10
24
 
11
- acts_as_favoritor works with Rails 4.0 onwards. You can add it to your `Gemfile` with:
25
+ `acts_as_favoritor` works with Rails 4.0 onwards. You can add it to your `Gemfile` with:
12
26
 
13
27
  ```ruby
14
28
  gem 'acts_as_favoritor'
@@ -40,6 +54,149 @@ This will create a Favorite model as well as a migration file.
40
54
 
41
55
  ## Usage
42
56
 
57
+ ### Setup
58
+
59
+ Add `acts_as_favoritable` to the models you want to be able to get favorited:
60
+
61
+ ```ruby
62
+ class User < ActiveRecord::Base
63
+ acts_as_favoritable
64
+ end
65
+
66
+ class Book < ActiveRecord::Base
67
+ acts_as_favoritable
68
+ end
69
+ ```
70
+
71
+ Specify which models can favorite other models by adding `acts_as_favoritor`:
72
+
73
+ ```ruby
74
+ class User < ActiveRecord::Base
75
+ acts_as_favoritor
76
+ end
77
+ ```
78
+
79
+ ### `acts_as_favoritor` methods
80
+
81
+ ```ruby
82
+ book = Book.find 1
83
+ user = User.find 1
84
+
85
+ # `user` favorites `book`.
86
+ user.favorite book
87
+
88
+ # `user` removes `book` from favorites.
89
+ user.remove_favorite book
90
+
91
+ # Whether `user` has marked `book` as his favorite. Returns `true` or `false`.
92
+ user.favorited? book
93
+
94
+ # Total number of favorites by `user`.
95
+ user.favorite_count
96
+
97
+ # Returnes `user`'s favorites that have not been blocked as an array of Favorite records.
98
+ user.all_favorites
99
+
100
+ # Returns all favorited objects of `user` as an array (unblocked). This can be a collection of different object types, eg: `User`, `Book`.
101
+ user.all_favorited
102
+
103
+ # Returns an array of Favorite records where the `favoritable_type` is `Book`.
104
+ user.favorites_by_type 'Book'
105
+
106
+ # 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`.
107
+ user.favorited_by_type 'Book'
108
+
109
+ # Returns the exact same result as `user.favorited_by_type 'User'`.
110
+ user.favorited_users
111
+
112
+ # Total number of favorited books by `user`.
113
+ user.favorited_by_type_count 'Book'
114
+
115
+ # Returns the exact same result as `user.favorited_by_type_count 'Book'`.
116
+ user.favorited_books_count
117
+
118
+ # Returns the Arel scope for favorites.
119
+ # This does not return the actual favorites, just the scope of favorited including the favoritables, essentially: `book.favorites.unblocked.includes(:favoritable)`.
120
+ book.favorites_scoped
121
+ ```
122
+
123
+ These methods take an optional hash parameter of ActiveRecord options (`:limit`, `:order`, etc...)
124
+
125
+ favorites_by_type, all_favorites, all_favorited, favorited_by_type
126
+
127
+ ### `acts_as_favoritable` methods
128
+
129
+ ```ruby
130
+ # Returns all favoritors of a model that `acts_as_favoritable`
131
+ book.favoritors
132
+
133
+ # Returns the Arel scope for favoritors. This does not return the actual favoritors, just the scope of favorited records including the favoritors, essentially: `book.favorited.includes(:favoritors)`.
134
+ book.favoritors_scoped
135
+
136
+ # Total number of favoritors.
137
+ book.favoritors_count
138
+
139
+ # Returns an array of records with type `User` following `book`.
140
+ book.favoritors_by_type 'User'
141
+
142
+ # Returns the exact same as `book.favoritors_by_type 'User'`.
143
+ book.user_favoritors
144
+
145
+ # Total number of favoritors with type `User`.
146
+ book.favoritors_by_type_count 'User'
147
+
148
+ # Returns the exact same as `book.favoritors_by_type_count 'User'`.
149
+ book.count_user_favoritors
150
+
151
+ To see is a model that acts_as_followable is followed by a model that acts_as_follower use the following
152
+ # Whether `book` has been favorited by `user`. Returns `true` or `false`.
153
+ book.favorited_by? user
154
+
155
+ # Block a favoritor
156
+ book.block user
157
+
158
+ # Unblock a favoritor
159
+ book.unblock user
160
+
161
+ # Returns an array including all blocked Favoritor records.
162
+ book.blocks
163
+
164
+ # Total number of `book`'s favoritors blocked.
165
+ book.blocked_favoritors_count
166
+ ```
167
+
168
+ These methods take an optional hash parameter of ActiveRecord options (`:limit`, `:order`, etc...)
169
+
170
+ favoritors_by_type, favoritors, blocks
171
+
172
+ ### `Favorite` model
173
+
174
+ ```ruby
175
+ # Scopes
176
+ ## Returns all Favorite records where `blocked` is `false`.
177
+ Favorite.unblocked
178
+ ## Returns all Favorite records where `blocked` is `true`.
179
+ Favorite.blocked
180
+ ## Returns an ordered array of the latest create Favorite records.
181
+ Favorite.descending
182
+
183
+ # Returns all Favorite records in an array, which have been created in a specified timeframe. Default is 2 weeks.
184
+ Favorite.recent
185
+ Favorite.recent 1.month.ago
186
+
187
+ # Returns all favorites of `user`, including those who were blocked.
188
+ Favorite.for_favoritor user
189
+
190
+ # Returns all favoritors of `book`, including those who were blocked.
191
+ Favorite.for_favoritable book
192
+ ```
193
+
194
+ ---
195
+
196
+ ## To Do List
197
+
198
+ * Allow Favorites to be scoped, supporting multiple sets of favorites between models.
199
+
43
200
  ---
44
201
 
45
202
  ## Contributors
@@ -92,7 +92,7 @@ module ActsAsFavoritor #:nodoc:
92
92
  end
93
93
 
94
94
  def unblock favoritor
95
- get_favorite_for(favoritor).try(:delete)
95
+ get_favorite_for(favoritor).update_attribute :blocked, false
96
96
  end
97
97
 
98
98
  def get_favorite_for favoritor
@@ -1,5 +1,5 @@
1
1
  module ActsAsFavoritor
2
2
 
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
 
5
5
  end
@@ -3,7 +3,7 @@ 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 :lists, default: [:favorites].to_yaml, null: false
6
+ t.string :scopes, default: [:favorites].to_yaml, null: false
7
7
  t.boolean :blocked, default: false, null: false
8
8
  t.timestamps
9
9
  end
@@ -3,7 +3,7 @@ class Favorite < ActiveRecord::Base
3
3
  extend ActsAsFavoritor::FavoritorLib
4
4
  extend ActsAsFavoritor::FavoriteScopes
5
5
 
6
- serialize :lists
6
+ serialize :scopes
7
7
 
8
8
  # NOTE: Favorites belong to the 'favoritable' and 'favoritor' interface
9
9
  belongs_to :favoritable, polymorphic: true
data/test/schema.rb CHANGED
@@ -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 'lists', default: [:favorites].to_yaml, null: false
8
+ t.string 'scopes', default: [:favorites].to_yaml, 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.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
@@ -108,7 +108,6 @@ files:
108
108
  - ".travis.yml"
109
109
  - CHANGELOG.md
110
110
  - Gemfile
111
- - Gemfile.lock
112
111
  - LICENSE
113
112
  - README.md
114
113
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,131 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- acts_as_favoritor (1.0.1)
5
- activerecord (>= 4.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- actioncable (5.1.3)
11
- actionpack (= 5.1.3)
12
- nio4r (~> 2.0)
13
- websocket-driver (~> 0.6.1)
14
- actionmailer (5.1.3)
15
- actionpack (= 5.1.3)
16
- actionview (= 5.1.3)
17
- activejob (= 5.1.3)
18
- mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 2.0)
20
- actionpack (5.1.3)
21
- actionview (= 5.1.3)
22
- activesupport (= 5.1.3)
23
- rack (~> 2.0)
24
- rack-test (~> 0.6.3)
25
- rails-dom-testing (~> 2.0)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.1.3)
28
- activesupport (= 5.1.3)
29
- builder (~> 3.1)
30
- erubi (~> 1.4)
31
- rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
- activejob (5.1.3)
34
- activesupport (= 5.1.3)
35
- globalid (>= 0.3.6)
36
- activemodel (5.1.3)
37
- activesupport (= 5.1.3)
38
- activerecord (5.1.3)
39
- activemodel (= 5.1.3)
40
- activesupport (= 5.1.3)
41
- arel (~> 8.0)
42
- activesupport (5.1.3)
43
- concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (~> 0.7)
45
- minitest (~> 5.1)
46
- tzinfo (~> 1.1)
47
- arel (8.0.0)
48
- builder (3.2.3)
49
- concurrent-ruby (1.0.5)
50
- erubi (1.6.1)
51
- factory_girl (4.8.0)
52
- activesupport (>= 3.0.0)
53
- globalid (0.4.0)
54
- activesupport (>= 4.2.0)
55
- i18n (0.8.6)
56
- loofah (2.0.3)
57
- nokogiri (>= 1.5.9)
58
- mail (2.6.6)
59
- mime-types (>= 1.16, < 4)
60
- method_source (0.8.2)
61
- mime-types (3.1)
62
- mime-types-data (~> 3.2015)
63
- mime-types-data (3.2016.0521)
64
- mini_portile2 (2.2.0)
65
- minitest (5.10.3)
66
- nio4r (2.1.0)
67
- nokogiri (1.8.0-x86-mingw32)
68
- mini_portile2 (~> 2.2.0)
69
- rack (2.0.3)
70
- rack-test (0.6.3)
71
- rack (>= 1.0)
72
- rails (5.1.3)
73
- actioncable (= 5.1.3)
74
- actionmailer (= 5.1.3)
75
- actionpack (= 5.1.3)
76
- actionview (= 5.1.3)
77
- activejob (= 5.1.3)
78
- activemodel (= 5.1.3)
79
- activerecord (= 5.1.3)
80
- activesupport (= 5.1.3)
81
- bundler (>= 1.3.0)
82
- railties (= 5.1.3)
83
- sprockets-rails (>= 2.0.0)
84
- rails-dom-testing (2.0.3)
85
- activesupport (>= 4.2.0)
86
- nokogiri (>= 1.6)
87
- rails-html-sanitizer (1.0.3)
88
- loofah (~> 2.0)
89
- railties (5.1.3)
90
- actionpack (= 5.1.3)
91
- activesupport (= 5.1.3)
92
- method_source
93
- rake (>= 0.8.7)
94
- thor (>= 0.18.1, < 2.0)
95
- rake (12.0.0)
96
- shoulda (3.5.0)
97
- shoulda-context (~> 1.0, >= 1.0.1)
98
- shoulda-matchers (>= 1.4.1, < 3.0)
99
- shoulda-context (1.2.2)
100
- shoulda-matchers (2.8.0)
101
- activesupport (>= 3.0.0)
102
- shoulda_create (0.0.9)
103
- sprockets (3.7.1)
104
- concurrent-ruby (~> 1.0)
105
- rack (> 1, < 3)
106
- sprockets-rails (3.2.0)
107
- actionpack (>= 4.0)
108
- activesupport (>= 4.0)
109
- sprockets (>= 3.0.0)
110
- sqlite3 (1.3.13-x86-mingw32)
111
- thor (0.20.0)
112
- thread_safe (0.3.6)
113
- tzinfo (1.2.3)
114
- thread_safe (~> 0.1)
115
- websocket-driver (0.6.5)
116
- websocket-extensions (>= 0.1.0)
117
- websocket-extensions (0.1.2)
118
-
119
- PLATFORMS
120
- x86-mingw32
121
-
122
- DEPENDENCIES
123
- acts_as_favoritor!
124
- factory_girl (~> 4.8)
125
- rails (>= 4.0)
126
- shoulda (~> 3.5)
127
- shoulda_create (~> 0.0)
128
- sqlite3 (~> 1.3)
129
-
130
- BUNDLED WITH
131
- 1.15.4