notification-handler 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f78c83fb0e90a1d9e7c0071f9cdf724f86f8250766bac83ac91461e566d7664
4
- data.tar.gz: 6bf1fff6ee138daeece4a1722ebf1cd723276e8c45380b683d0f16886a288722
3
+ metadata.gz: 487a429c1a9affdd1a4134cf9f25db17f959c348235c1e84030d6ae8f864d11b
4
+ data.tar.gz: 789a52f5f28e9eaeca91729f7780e8ce002aba23d1f717fb4ebad78cf29d557f
5
5
  SHA512:
6
- metadata.gz: 78192992cfcd20e34c9f3698ad77622f7ab6fb4540803e5ca93d1fe2dea169ae8f9be954ae2db48d2b8f685998248272b1ba8a44aa4e9cffbe6ab582bedace71
7
- data.tar.gz: b5c7f971d303ac93fb02761ffbb6dfbd549244bf521705064b92d815910827c0b11b8928be5a2fac6c2626879655b3e521b2c0b68927c20e63f42cb1562bab77
6
+ metadata.gz: f953fa2ea9805a60524117a04313b9b26eb2349fbe1a606d13daab4f5fd5e8e03a209b596f23f235a1c2774445c3b286494070369a3e54962f9910af426b9b26
7
+ data.tar.gz: c578e829f2cf2aad8d73ba459289db0c658b324a78b24217149757fd87d64a1533ebac9faada3e7756a2f45983ab408e3562af268bd8e72de3501238d759a533
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 Jonas Hübotter
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Jonas Hübotter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,260 +1,260 @@
1
- # NotificationHandler
2
-
3
- [![Gem Version](https://badge.fury.io/rb/notification-handler.svg)](https://badge.fury.io/rb/notification-handler) <img src="https://travis-ci.org/jonhue/notifications-rails.svg?branch=master" />
4
-
5
- Create and modify your notifications through a simple API.
6
-
7
- ---
8
-
9
- ## Table of Contents
10
-
11
- * [Installation](#installation)
12
- * [Usage](#usage)
13
- * [`Notification` API](#notification-api)
14
- * [`notification_target`](#notification_target)
15
- * [`notification_object`](#notification_object)
16
- * [Groups](#groups)
17
- * [Defining a group](#defining-a-group)
18
- * [Using a group](#using-a-group)
19
- * [Caching](#caching)
20
- * [Configuration](#configuration)
21
- * [To Do](#to-do)
22
- * [Contributing](#contributing)
23
- * [Contributors](#contributors)
24
- * [Semantic versioning](#semantic-versioning)
25
- * [License](#license)
26
-
27
- ---
28
-
29
- ## Installation
30
-
31
- NotificationHandler works with Rails 5 onwards. You can add it to your `Gemfile` with:
32
-
33
- ```ruby
34
- gem 'notification-handler'
35
- ```
36
-
37
- And then execute:
38
-
39
- $ bundle
40
-
41
- Or install it yourself as:
42
-
43
- $ gem install notification-handler
44
-
45
- If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
46
-
47
- ```ruby
48
- gem 'notification-handler', github: 'jonhue/notifications-rails'
49
- ```
50
-
51
- Now run the generator:
52
-
53
- $ rails g notification_handler:install
54
-
55
- To wrap things up, migrate the changes to your database:
56
-
57
- $ rails db:migrate
58
-
59
- ---
60
-
61
- ## Usage
62
-
63
- ### `Notification` API
64
-
65
- You can use all the ActiveRecord methods you know and love on your `Notification` class. So creating a new notification is dead simple:
66
-
67
- ```ruby
68
- notification = Notification.new
69
- ```
70
-
71
- Every `Notification` object has a `target` record. This target record is the object, that this notification belongs to (or targets). Usually it's a user, but it can be a record of any class:
72
-
73
- ```ruby
74
- notification.target = User.first
75
- ```
76
-
77
- To store information in your `Notification` record you can use the `metadata` attribute that gets serialized as a `Hash`:
78
-
79
- ```ruby
80
- notification.metadata = {
81
- title: 'My first notification',
82
- content: "It looks great, doesn't it?"
83
- }
84
- ```
85
-
86
- Another form of adding information is by associating an object to the notification. This can be a record of any class you like:
87
-
88
- ```ruby
89
- notification.object = Recipe.first
90
- ```
91
-
92
- The `read` attribute determines whether a notification has been seen or not:
93
-
94
- ```ruby
95
- notification.read = true
96
- notification.read? # true
97
- notification.unread? # false
98
- ```
99
-
100
- You can use scopes to filter for read or unread notifications:
101
-
102
- ```ruby
103
- # Return all read notifications
104
- Notification.read
105
-
106
- # Return all unread notifications
107
- Notification.unread
108
-
109
- # Number of unread notifications
110
- Notification.unread.count
111
- ```
112
-
113
- ### `notification_target`
114
-
115
- To use records of an ActiveRecord class as notification targets, add the following to your class:
116
-
117
- ```ruby
118
- class User < ApplicationRecord
119
- notification_target
120
- end
121
- ```
122
-
123
- Now belonging notifications are easy to access:
124
-
125
- ```ruby
126
- notifications = User.first.notifications
127
- ```
128
-
129
- You can create a notification from a `target`:
130
-
131
- ```ruby
132
- User.first.notify object: Recipe.first
133
- ```
134
-
135
- ...
136
-
137
- ### `notification_object`
138
-
139
- When using records of an ActiveRecord class as notification objects, add this to your class:
140
-
141
- ```ruby
142
- class Recipe < ApplicationRecord
143
- notification_object
144
- end
145
- ```
146
-
147
- Now associated notifications are easy to access:
148
-
149
- ```ruby
150
- notifications = Recipe.first.belonging_notifications
151
- ```
152
-
153
- ...
154
-
155
- ### Groups
156
-
157
- Groups are a powerful way to bulk-create notifications for multiple objects that don't necessarily have a common class.
158
-
159
- #### Defining a group
160
-
161
- You define groups in your `NotificationHandler` configuration:
162
-
163
- ```ruby
164
- NotificationHandler.configure do |config|
165
- config.define_group :subscribers, User.where(subscriber: true)
166
- end
167
- ```
168
-
169
- When creating a notification for the group `:subscribers`, one notification will be added for every target that fulfills this scope: `User.where(subscriber: true)`. You can also target objects from different classes:
170
-
171
- ```ruby
172
- NotificationHandler.configure do |config|
173
- config.define_group :subscribers, User.where(subscriber: true) + Admin.all
174
- end
175
- ```
176
-
177
- #### Using a group
178
-
179
- Bulk-creation of notifications for a certain group is fairly simple:
180
-
181
- ```ruby
182
- notification = Notification.create object: Recipe.first, group: :subscribers
183
- ```
184
-
185
- **Note:** You are not able to set the `target` attribute when a `group` has been specified.
186
-
187
- ### Caching
188
-
189
- You can cache the amount of unread and read notifications for notification targets by settings the [`cache`](#configuration) configuration option to `true`.
190
-
191
- Then add the following columns to the database tables of ActiveRecord classes acting as notification targets:
192
-
193
- ```ruby
194
- add_column :user, :read_notification_count, :integer
195
- add_column :user, :unread_notification_count, :integer
196
- ```
197
-
198
- ---
199
-
200
- ## Configuration
201
-
202
- You can configure NotificationHandler by passing a block to `configure`. This can be done in `config/initializers/notification-handler.rb`:
203
-
204
- ```ruby
205
- NotificationHandler.configure do |config|
206
- config.cache = true
207
- end
208
- ```
209
-
210
- **`cache`** Cache amount of unread and read notifications for notification targets. Takes a boolean. Defaults to `false`.
211
-
212
- ---
213
-
214
- ## To Do
215
-
216
- [Here](https://github.com/jonhue/notifications-rails/projects/2) is the full list of current projects.
217
-
218
- To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
219
-
220
- ---
221
-
222
- ## Contributing
223
-
224
- We hope that you will consider contributing to NotificationHandler. Please read this short overview for some information about how to get started:
225
-
226
- [Learn more about contributing to this repository](https://github.com/jonhue/notifications-rails/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/notifications-rails/blob/master/CODE_OF_CONDUCT.md)
227
-
228
- ### Contributors
229
-
230
- Give the people some :heart: who are working on this project. See them all at:
231
-
232
- https://github.com/jonhue/notifications-rails/graphs/contributors
233
-
234
- ### Semantic Versioning
235
-
236
- NotificationHandler follows Semantic Versioning 2.0 as defined at http://semver.org.
237
-
238
- ## License
239
-
240
- MIT License
241
-
242
- Copyright (c) 2017 Jonas Hübotter
243
-
244
- Permission is hereby granted, free of charge, to any person obtaining a copy
245
- of this software and associated documentation files (the "Software"), to deal
246
- in the Software without restriction, including without limitation the rights
247
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
248
- copies of the Software, and to permit persons to whom the Software is
249
- furnished to do so, subject to the following conditions:
250
-
251
- The above copyright notice and this permission notice shall be included in all
252
- copies or substantial portions of the Software.
253
-
254
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
255
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
256
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
257
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
258
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
259
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
260
- SOFTWARE.
1
+ # NotificationHandler
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/notification-handler.svg)](https://badge.fury.io/rb/notification-handler) <img src="https://travis-ci.org/jonhue/notifications-rails.svg?branch=master" />
4
+
5
+ Create and modify your notifications through a simple API.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ * [`Notification` API](#notification-api)
14
+ * [`notification_target`](#notification_target)
15
+ * [`notification_object`](#notification_object)
16
+ * [Groups](#groups)
17
+ * [Defining a group](#defining-a-group)
18
+ * [Using a group](#using-a-group)
19
+ * [Caching](#caching)
20
+ * [Configuration](#configuration)
21
+ * [To Do](#to-do)
22
+ * [Contributing](#contributing)
23
+ * [Contributors](#contributors)
24
+ * [Semantic versioning](#semantic-versioning)
25
+ * [License](#license)
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ NotificationHandler works with Rails 5 onwards. You can add it to your `Gemfile` with:
32
+
33
+ ```ruby
34
+ gem 'notification-handler'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install notification-handler
44
+
45
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
46
+
47
+ ```ruby
48
+ gem 'notification-handler', github: 'jonhue/notifications-rails'
49
+ ```
50
+
51
+ Now run the generator:
52
+
53
+ $ rails g notification_handler:install
54
+
55
+ To wrap things up, migrate the changes to your database:
56
+
57
+ $ rails db:migrate
58
+
59
+ ---
60
+
61
+ ## Usage
62
+
63
+ ### `Notification` API
64
+
65
+ You can use all the ActiveRecord methods you know and love on your `Notification` class. So creating a new notification is dead simple:
66
+
67
+ ```ruby
68
+ notification = Notification.new
69
+ ```
70
+
71
+ Every `Notification` object has a `target` record. This target record is the object, that this notification belongs to (or targets). Usually it's a user, but it can be a record of any class:
72
+
73
+ ```ruby
74
+ notification.target = User.first
75
+ ```
76
+
77
+ To store information in your `Notification` record you can use the `metadata` attribute that gets serialized as a `Hash`:
78
+
79
+ ```ruby
80
+ notification.metadata = {
81
+ title: 'My first notification',
82
+ content: "It looks great, doesn't it?"
83
+ }
84
+ ```
85
+
86
+ Another form of adding information is by associating an object to the notification. This can be a record of any class you like:
87
+
88
+ ```ruby
89
+ notification.object = Recipe.first
90
+ ```
91
+
92
+ The `read` attribute determines whether a notification has been seen or not:
93
+
94
+ ```ruby
95
+ notification.read = true
96
+ notification.read? # true
97
+ notification.unread? # false
98
+ ```
99
+
100
+ You can use scopes to filter for read or unread notifications:
101
+
102
+ ```ruby
103
+ # Return all read notifications
104
+ Notification.read
105
+
106
+ # Return all unread notifications
107
+ Notification.unread
108
+
109
+ # Number of unread notifications
110
+ Notification.unread.count
111
+ ```
112
+
113
+ ### `notification_target`
114
+
115
+ To use records of an ActiveRecord class as notification targets, add the following to your class:
116
+
117
+ ```ruby
118
+ class User < ApplicationRecord
119
+ notification_target
120
+ end
121
+ ```
122
+
123
+ Now belonging notifications are easy to access:
124
+
125
+ ```ruby
126
+ notifications = User.first.notifications
127
+ ```
128
+
129
+ You can create a notification from a `target`:
130
+
131
+ ```ruby
132
+ User.first.notify object: Recipe.first
133
+ ```
134
+
135
+ ...
136
+
137
+ ### `notification_object`
138
+
139
+ When using records of an ActiveRecord class as notification objects, add this to your class:
140
+
141
+ ```ruby
142
+ class Recipe < ApplicationRecord
143
+ notification_object
144
+ end
145
+ ```
146
+
147
+ Now associated notifications are easy to access:
148
+
149
+ ```ruby
150
+ notifications = Recipe.first.belonging_notifications
151
+ ```
152
+
153
+ ...
154
+
155
+ ### Groups
156
+
157
+ Groups are a powerful way to bulk-create notifications for multiple objects that don't necessarily have a common class.
158
+
159
+ #### Defining a group
160
+
161
+ You define groups in your `NotificationHandler` configuration:
162
+
163
+ ```ruby
164
+ NotificationHandler.configure do |config|
165
+ config.define_group :subscribers, User.where(subscriber: true)
166
+ end
167
+ ```
168
+
169
+ When creating a notification for the group `:subscribers`, one notification will be added for every target that fulfills this scope: `User.where(subscriber: true)`. You can also target objects from different classes:
170
+
171
+ ```ruby
172
+ NotificationHandler.configure do |config|
173
+ config.define_group :subscribers, User.where(subscriber: true) + Admin.all
174
+ end
175
+ ```
176
+
177
+ #### Using a group
178
+
179
+ Bulk-creation of notifications for a certain group is fairly simple:
180
+
181
+ ```ruby
182
+ notification = Notification.create object: Recipe.first, group: :subscribers
183
+ ```
184
+
185
+ **Note:** You are not able to set the `target` attribute when a `group` has been specified.
186
+
187
+ ### Caching
188
+
189
+ You can cache the amount of unread and read notifications for notification targets by settings the [`cache`](#configuration) configuration option to `true`.
190
+
191
+ Then add the following columns to the database tables of ActiveRecord classes acting as notification targets:
192
+
193
+ ```ruby
194
+ add_column :user, :read_notification_count, :integer
195
+ add_column :user, :unread_notification_count, :integer
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Configuration
201
+
202
+ You can configure NotificationHandler by passing a block to `configure`. This can be done in `config/initializers/notification-handler.rb`:
203
+
204
+ ```ruby
205
+ NotificationHandler.configure do |config|
206
+ config.cache = true
207
+ end
208
+ ```
209
+
210
+ **`cache`** Cache amount of unread and read notifications for notification targets. Takes a boolean. Defaults to `false`.
211
+
212
+ ---
213
+
214
+ ## To Do
215
+
216
+ [Here](https://github.com/jonhue/notifications-rails/projects/2) is the full list of current projects.
217
+
218
+ To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
219
+
220
+ ---
221
+
222
+ ## Contributing
223
+
224
+ We hope that you will consider contributing to NotificationHandler. Please read this short overview for some information about how to get started:
225
+
226
+ [Learn more about contributing to this repository](https://github.com/jonhue/notifications-rails/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/notifications-rails/blob/master/CODE_OF_CONDUCT.md)
227
+
228
+ ### Contributors
229
+
230
+ Give the people some :heart: who are working on this project. See them all at:
231
+
232
+ https://github.com/jonhue/notifications-rails/graphs/contributors
233
+
234
+ ### Semantic Versioning
235
+
236
+ NotificationHandler follows Semantic Versioning 2.0 as defined at http://semver.org.
237
+
238
+ ## License
239
+
240
+ MIT License
241
+
242
+ Copyright (c) 2017 Jonas Hübotter
243
+
244
+ Permission is hereby granted, free of charge, to any person obtaining a copy
245
+ of this software and associated documentation files (the "Software"), to deal
246
+ in the Software without restriction, including without limitation the rights
247
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
248
+ copies of the Software, and to permit persons to whom the Software is
249
+ furnished to do so, subject to the following conditions:
250
+
251
+ The above copyright notice and this permission notice shall be included in all
252
+ copies or substantial portions of the Software.
253
+
254
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
255
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
256
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
257
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
258
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
259
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
260
+ SOFTWARE.