notification-settings 1.2.4 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +84 -271
- data/lib/notifications-rails.rb +6 -0
- metadata +124 -36
- data/CHANGELOG.md +0 -59
- data/app/models/notification_settings/setting.rb +0 -13
- data/app/models/notification_settings/subscription.rb +0 -13
- data/lib/generators/notification_settings/install_generator.rb +0 -43
- data/lib/generators/templates/install/README.md +0 -1
- data/lib/generators/templates/install/initializer.rb +0 -24
- data/lib/generators/templates/install/notifications_migration.rb.erb +0 -29
- data/lib/notification-settings.rb +0 -15
- data/lib/notification_settings/configuration.rb +0 -32
- data/lib/notification_settings/engine.rb +0 -7
- data/lib/notification_settings/notification_library.rb +0 -72
- data/lib/notification_settings/notification_scopes.rb +0 -30
- data/lib/notification_settings/setting_library.rb +0 -28
- data/lib/notification_settings/subscribable.rb +0 -42
- data/lib/notification_settings/subscriber.rb +0 -30
- data/lib/notification_settings/subscription_library.rb +0 -25
- data/lib/notification_settings/target.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f51d7d4a8dca20f5f20c248b34ea9f9290e8844285dfd93b93111d3f1c27cd
|
4
|
+
data.tar.gz: bd923e061018cffba1249a8f728db477acad1a3eea9879f7965bc786245c54ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4f50488e3f1d1b4df6f290e02fedbe56a544cbd870e7f7d59b22787da3464663258abe3b4e12ce2c38478cf0753a6973556d0b3fd3e7f73ce7b1facedb097b0
|
7
|
+
data.tar.gz: 1c55207dc022117e228e7f39753ae322999d6dae499e53b78cfb3bdf4830eb8404b6b035e9ab19dbb096489430ed9e0abeb3adc6e50b074ba60c8d3ada3bab71
|
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,271 +1,84 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
# Return records with `'follow'` as category
|
87
|
-
Notification.follow_category
|
88
|
-
```
|
89
|
-
|
90
|
-
### Settings
|
91
|
-
|
92
|
-
You can disable notifications for a given notification target:
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
s = User.first.notification_setting
|
96
|
-
s.settings[:enabled] = false
|
97
|
-
```
|
98
|
-
|
99
|
-
This will prevent you from creating any new notifications with this user as target.
|
100
|
-
|
101
|
-
#### Category specific settings
|
102
|
-
|
103
|
-
A user can also have category specific settings:
|
104
|
-
|
105
|
-
```ruby
|
106
|
-
s.category_settings[:category] = { enabled: false }
|
107
|
-
```
|
108
|
-
|
109
|
-
#### Pusher specific settings
|
110
|
-
|
111
|
-
He can have global or category specific pusher settings:
|
112
|
-
|
113
|
-
```ruby
|
114
|
-
s.settings[:ActionMailer] = false
|
115
|
-
s.category_settings[:category] = { ActionMailer: false }
|
116
|
-
```
|
117
|
-
|
118
|
-
#### Updating settings
|
119
|
-
|
120
|
-
...
|
121
|
-
|
122
|
-
### Subscriptions
|
123
|
-
|
124
|
-
Subscriptions are a way to better handle settings for notifications from different objects to one notification target.
|
125
|
-
|
126
|
-
This is how to subscribe/unsubscribe a target to an object:
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
User.first.subscribe Recipe.first
|
130
|
-
User.first.unsubscribe Recipe.first
|
131
|
-
```
|
132
|
-
|
133
|
-
Now you can easily notify all subscribers from the subscribable object:
|
134
|
-
|
135
|
-
```ruby
|
136
|
-
Recipe.first.notify_subscribers push: :ActionMailer
|
137
|
-
```
|
138
|
-
|
139
|
-
Let's assume that we have a group which has multiple chats. When sending notifications to subscribers of a given chat, we only want them to get notified. But when sending notifications about the group, we want to have everyone notified, that is either subscribed to the group or subscribed to one of its chats. To do that you have to add the `private` method `notification_dependents` to your model (in this case `Group`) and return an array of ActiveRecord objects whose subscribers should receive notifications for objects of this class.
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
has_many :chats
|
143
|
-
has_many :talks
|
144
|
-
|
145
|
-
private
|
146
|
-
|
147
|
-
def notification_dependents
|
148
|
-
self.chats
|
149
|
-
end
|
150
|
-
```
|
151
|
-
|
152
|
-
It is possible to override that behavior when notifying subscribers:
|
153
|
-
|
154
|
-
```ruby
|
155
|
-
# Disable notification dependents
|
156
|
-
Group.first.notify_subscribers dependents: nil
|
157
|
-
|
158
|
-
# Override notification dependents
|
159
|
-
Group.first.notify_subscribers dependents: Group.first.chats + Group.first.talks
|
160
|
-
```
|
161
|
-
|
162
|
-
You can customize settings for a single subscription just as you would for a notification target:
|
163
|
-
|
164
|
-
```ruby
|
165
|
-
s = User.first.notification_subscriptions.first.notification_setting
|
166
|
-
s.settings[:enabled] = false
|
167
|
-
```
|
168
|
-
|
169
|
-
[Learn more](#settings)
|
170
|
-
|
171
|
-
### Status
|
172
|
-
|
173
|
-
NotificationSettings comes with a handy feature called Status. The status of a record can temporarily disable the ability to create notifications for or to push notifications of a target.
|
174
|
-
|
175
|
-
This is how to define a status:
|
176
|
-
|
177
|
-
```ruby
|
178
|
-
User.first.notification_setting.status = 'do not disturb'
|
179
|
-
User.first.notification_setting.save
|
180
|
-
```
|
181
|
-
|
182
|
-
**Note:** You can set `status` to any string you like.
|
183
|
-
|
184
|
-
`status` has three possible values that are being used as defaults. Normally it defaults to `'online'`. If the `last_seen` [configuration](#configuration) option has been set, it can also default to `'idle'` or `'offline'` depending on the `idle_after` and `offline_after` [configuration](#configuration) options.
|
185
|
-
|
186
|
-
If you have set `status` to a custom value, you can get back to using the defaults by setting it back to `nil`.
|
187
|
-
|
188
|
-
You can define statuses that prevent creating new notifications for a target and statuses that just prevent pushing them:
|
189
|
-
|
190
|
-
```ruby
|
191
|
-
NotificationSettings.configure do |config|
|
192
|
-
config.do_not_notify_statuses = ['do not notify']
|
193
|
-
config.do_not_push_statuses = ['do not disturb']
|
194
|
-
end
|
195
|
-
```
|
196
|
-
|
197
|
-
---
|
198
|
-
|
199
|
-
## Configuration
|
200
|
-
|
201
|
-
You can configure NotificationSettings by passing a block to `configure`. This can be done in `config/initializers/notification-settings.rb`:
|
202
|
-
|
203
|
-
```ruby
|
204
|
-
NotificationSettings.configure do |config|
|
205
|
-
config.default_category = 'notification'
|
206
|
-
end
|
207
|
-
```
|
208
|
-
|
209
|
-
**`default_category`** Choose your default notification category. Takes a string. Defaults to `'notification'`.
|
210
|
-
|
211
|
-
### Status
|
212
|
-
|
213
|
-
**`idle_after`** Time duration without activity after which the status defaults to `'idle'`. Takes a time. Defaults to `10.minutes`.
|
214
|
-
|
215
|
-
**`offline_after`** Time duration without activity after which the status defaults to `'offline'`. Takes a time. Defaults to `3.hours`.
|
216
|
-
|
217
|
-
**`last_seen`** Stringified datetime attribute name of `object` that defines the time of the last activity. Takes a string. Defaults to `'last_seen'`.
|
218
|
-
|
219
|
-
**`do_not_notify_statuses`** Array of possible statuses that will prevent creating notifications for a target. Takes an array of strings. Defaults to `[]`.
|
220
|
-
|
221
|
-
**`do_not_push_statuses`** Array of possible statuses that will prevent pushing notifications of a target. Takes an array of strings. Defaults to `['do not disturb']`
|
222
|
-
|
223
|
-
---
|
224
|
-
|
225
|
-
## To Do
|
226
|
-
|
227
|
-
[Here](https://github.com/jonhue/notifications-rails/projects/4) is the full list of current projects.
|
228
|
-
|
229
|
-
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
|
230
|
-
|
231
|
-
---
|
232
|
-
|
233
|
-
## Contributing
|
234
|
-
|
235
|
-
We hope that you will consider contributing to NotificationSettings. Please read this short overview for some information about how to get started:
|
236
|
-
|
237
|
-
[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)
|
238
|
-
|
239
|
-
### Contributors
|
240
|
-
|
241
|
-
Give the people some :heart: who are working on this project. See them all at:
|
242
|
-
|
243
|
-
https://github.com/jonhue/notifications-rails/graphs/contributors
|
244
|
-
|
245
|
-
### Semantic Versioning
|
246
|
-
|
247
|
-
NotificationSettings follows Semantic Versioning 2.0 as defined at http://semver.org.
|
248
|
-
|
249
|
-
## License
|
250
|
-
|
251
|
-
MIT License
|
252
|
-
|
253
|
-
Copyright (c) 2017 Jonas Hübotter
|
254
|
-
|
255
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
256
|
-
of this software and associated documentation files (the "Software"), to deal
|
257
|
-
in the Software without restriction, including without limitation the rights
|
258
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
259
|
-
copies of the Software, and to permit persons to whom the Software is
|
260
|
-
furnished to do so, subject to the following conditions:
|
261
|
-
|
262
|
-
The above copyright notice and this permission notice shall be included in all
|
263
|
-
copies or substantial portions of the Software.
|
264
|
-
|
265
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
266
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
267
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
268
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
269
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
270
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
271
|
-
SOFTWARE.
|
1
|
+
# notifications-rails
|
2
|
+
|
3
|
+
notifications-rails is the most powerful notification library for Rails. It offers not only simple APIs to create and render notifications but also supports user-integration and cross-platform delivery of notifications.
|
4
|
+
|
5
|
+
## Philosophy
|
6
|
+
|
7
|
+
notifications-rails has been built with modularity in mind. It currently consists of four components each of which bringing one essential functionality to the integration of notifications in your Rails app.
|
8
|
+
|
9
|
+
**[notification-handler](notification-handler):** Create and modify your notifications through a simple API.
|
10
|
+
|
11
|
+
**[notification-renderer](notification-renderer):** Render your notifications in various contexts.
|
12
|
+
|
13
|
+
**[notification-pusher](notification-pusher):** Deliver your notifications to various services, including [Email](notification-pusher/notification-pusher-actionmailer) and [OneSignal](notification-pusher/notification-pusher-onesignal).
|
14
|
+
|
15
|
+
**[notification-settings](notification-settings):** Integrates with your authentication solution to craft a personalized user notification platform.
|
16
|
+
|
17
|
+
You may just use the components you actually need, or instead use this gem to bundle everything for a complete notification solution.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
You can add notifications-rails to your `Gemfile` with:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'notifications-rails'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then run:
|
28
|
+
|
29
|
+
$ bundle install
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install notifications-rails
|
34
|
+
|
35
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
gem 'notifications-rails', github: 'jonhue/notifications-rails'
|
39
|
+
```
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
Details on usage are provided in the [documentation](#philosophy) of the specific modules.
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
To start development you first have to fork this repository and locally clone your fork.
|
48
|
+
|
49
|
+
Install the projects dependencies by running:
|
50
|
+
|
51
|
+
$ bundle install
|
52
|
+
|
53
|
+
### Testing
|
54
|
+
|
55
|
+
Tests are written with RSpec. Integration tests are located in `/spec`, unit tests can be found in `<module>/spec`.
|
56
|
+
|
57
|
+
To run all tests:
|
58
|
+
|
59
|
+
$ ./rspec
|
60
|
+
|
61
|
+
To run RuboCop:
|
62
|
+
|
63
|
+
$ bundle exec rubocop
|
64
|
+
|
65
|
+
You can find all commands run by the CI workflow in `.github/workflows/ci.yml`.
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
We warmly welcome everyone who is intersted in contributing. Please reference our [contributing guidelines](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md).
|
70
|
+
|
71
|
+
## Releases
|
72
|
+
|
73
|
+
[Here](https://github.com/jonhue/notifications-rails/releases) you can find details on all past releases. Unreleased breaking changes that are on the current master can be found [here](CHANGELOG.md).
|
74
|
+
|
75
|
+
notifications-rails follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our [security policy](SECURITY.md).
|
76
|
+
|
77
|
+
### Publishing
|
78
|
+
|
79
|
+
1. Review breaking changes and deprecations in `CHANGELOG.md`.
|
80
|
+
1. Change the gem version in `VERSION`.
|
81
|
+
1. Reset `CHANGELOG.md`.
|
82
|
+
1. Create a pull request to merge the changes into `master`.
|
83
|
+
1. After the pull request was merged, create a new release listing the breaking changes and commits on `master` since the last release.
|
84
|
+
1. The release workflow will publish the gems to RubyGems.
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.3
|
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:
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -52,78 +52,167 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.6'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '5.0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3.6'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5.0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: notification-handler
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
79
|
- - '='
|
60
80
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
81
|
+
version: 3.0.3
|
62
82
|
type: :runtime
|
63
83
|
prerelease: false
|
64
84
|
version_requirements: !ruby/object:Gem::Requirement
|
65
85
|
requirements:
|
66
86
|
- - '='
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
88
|
+
version: 3.0.3
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
90
|
+
name: railties
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
72
92
|
requirements:
|
73
|
-
- - "
|
93
|
+
- - ">="
|
74
94
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
95
|
+
version: '5.0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '5.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: factory_bot
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pry
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
76
124
|
type: :development
|
77
125
|
prerelease: false
|
78
126
|
version_requirements: !ruby/object:Gem::Requirement
|
79
127
|
requirements:
|
80
|
-
- - "
|
128
|
+
- - ">="
|
81
129
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rails
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: rspec-rails
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
83
159
|
- !ruby/object:Gem::Dependency
|
84
160
|
name: rubocop
|
85
161
|
requirement: !ruby/object:Gem::Requirement
|
86
162
|
requirements:
|
87
|
-
- - "
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: rubocop-rspec
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: sqlite3
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
88
192
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
193
|
+
version: '0'
|
90
194
|
type: :development
|
91
195
|
prerelease: false
|
92
196
|
version_requirements: !ruby/object:Gem::Requirement
|
93
197
|
requirements:
|
94
|
-
- - "
|
198
|
+
- - ">="
|
95
199
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0
|
200
|
+
version: '0'
|
97
201
|
description: Integrates with your authentication solution to craft a personalized
|
98
202
|
user notification platform.
|
99
|
-
email:
|
203
|
+
email: jonas.huebotter@gmail.com
|
100
204
|
executables: []
|
101
205
|
extensions: []
|
102
206
|
extra_rdoc_files: []
|
103
207
|
files:
|
104
|
-
- CHANGELOG.md
|
105
208
|
- LICENSE
|
106
209
|
- README.md
|
107
|
-
-
|
108
|
-
- app/models/notification_settings/subscription.rb
|
109
|
-
- lib/generators/notification_settings/install_generator.rb
|
110
|
-
- lib/generators/templates/install/README.md
|
111
|
-
- lib/generators/templates/install/initializer.rb
|
112
|
-
- lib/generators/templates/install/notifications_migration.rb.erb
|
113
|
-
- lib/notification-settings.rb
|
114
|
-
- lib/notification_settings/configuration.rb
|
115
|
-
- lib/notification_settings/engine.rb
|
116
|
-
- lib/notification_settings/notification_library.rb
|
117
|
-
- lib/notification_settings/notification_scopes.rb
|
118
|
-
- lib/notification_settings/setting_library.rb
|
119
|
-
- lib/notification_settings/subscribable.rb
|
120
|
-
- lib/notification_settings/subscriber.rb
|
121
|
-
- lib/notification_settings/subscription_library.rb
|
122
|
-
- lib/notification_settings/target.rb
|
210
|
+
- lib/notifications-rails.rb
|
123
211
|
homepage: https://github.com/jonhue/notifications-rails/tree/master/notification-settings
|
124
212
|
licenses:
|
125
213
|
- MIT
|
126
|
-
metadata:
|
214
|
+
metadata:
|
215
|
+
github_repo: ssh://github.com/jonhue/notifications-rails
|
127
216
|
post_install_message:
|
128
217
|
rdoc_options: []
|
129
218
|
require_paths:
|
@@ -132,15 +221,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
221
|
requirements:
|
133
222
|
- - ">="
|
134
223
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
224
|
+
version: 2.2.2
|
136
225
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
226
|
requirements:
|
138
227
|
- - ">="
|
139
228
|
- !ruby/object:Gem::Version
|
140
229
|
version: '0'
|
141
230
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.7.4
|
231
|
+
rubygems_version: 3.1.4
|
144
232
|
signing_key:
|
145
233
|
specification_version: 4
|
146
234
|
summary: Integrates with your authentication solution to craft a personalized user
|
data/CHANGELOG.md
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
### master
|
4
|
-
|
5
|
-
* nothing yet
|
6
|
-
|
7
|
-
### 1.2.2 - 2018/01/02
|
8
|
-
|
9
|
-
* bugfixes
|
10
|
-
* fixed `subscribe' method
|
11
|
-
|
12
|
-
### 1.2.1 - 2018/01/02
|
13
|
-
|
14
|
-
* bugfixes
|
15
|
-
* fixed `undefined method 'create!' for nil:NilClass` when creating `notification_target` objects
|
16
|
-
|
17
|
-
### 1.2.0 - 2018/01/02
|
18
|
-
|
19
|
-
* features
|
20
|
-
* added dependents functionality to subscribers feature
|
21
|
-
* bugfixes
|
22
|
-
* fixed `uninitialized constant NotificationSettings::Object`
|
23
|
-
|
24
|
-
### 1.1.2 - 2018/01/01
|
25
|
-
|
26
|
-
* bugfixes
|
27
|
-
* fixed length of indexes in generated migration files
|
28
|
-
|
29
|
-
### 1.0.0 - 2017/12/28
|
30
|
-
|
31
|
-
* bugfixes
|
32
|
-
|
33
|
-
### 1.0.0.beta6 - 2017/12/28
|
34
|
-
|
35
|
-
* bugfixes
|
36
|
-
* fix lib loading problems
|
37
|
-
|
38
|
-
### 1.0.0.beta5 - 2017/12/28
|
39
|
-
|
40
|
-
* bugfixes
|
41
|
-
* fix generators
|
42
|
-
* fix lib loading problems
|
43
|
-
* fix syntax errors
|
44
|
-
|
45
|
-
### 1.0.0.beta4 - 2017/12/27
|
46
|
-
|
47
|
-
* features
|
48
|
-
* add settings functionality
|
49
|
-
* add `category` attribute to `Notification` instances
|
50
|
-
* add subscription functonality
|
51
|
-
|
52
|
-
### 1.0.0.beta3 - 2017/12/25
|
53
|
-
|
54
|
-
* features
|
55
|
-
* add `Setting` ActiveRecord model
|
56
|
-
|
57
|
-
### 1.0.0.beta1 - 2017/12/22
|
58
|
-
|
59
|
-
* initial release
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class NotificationSettings::Setting < ActiveRecord::Base
|
2
|
-
|
3
|
-
self.table_name = 'notification_settings_settings'
|
4
|
-
|
5
|
-
include NotificationSettings::SettingLibrary
|
6
|
-
|
7
|
-
serialize :settings, Hash
|
8
|
-
serialize :category_settings, Hash
|
9
|
-
|
10
|
-
belongs_to :object, polymorphic: true, optional: true
|
11
|
-
belongs_to :subscription, optional: true
|
12
|
-
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class NotificationSettings::Subscription < ActiveRecord::Base
|
2
|
-
|
3
|
-
self.table_name = 'notification_settings_subscriptions'
|
4
|
-
|
5
|
-
include NotificationSettings::SubscriptionLibrary
|
6
|
-
|
7
|
-
belongs_to :subscriber, polymorphic: true
|
8
|
-
belongs_to :subscribable, polymorphic: true
|
9
|
-
|
10
|
-
has_many :notifications, class_name: '::Notification'
|
11
|
-
has_one :notification_setting, class_name: 'Setting'
|
12
|
-
|
13
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
|
4
|
-
module NotificationSettings
|
5
|
-
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
|
8
|
-
include Rails::Generators::Migration
|
9
|
-
|
10
|
-
source_root File.join File.dirname(__FILE__), '../templates/install'
|
11
|
-
desc 'Install NotificationSettings'
|
12
|
-
|
13
|
-
def self.next_migration_number dirname
|
14
|
-
if ActiveRecord::Base.timestamped_migrations
|
15
|
-
Time.now.utc.strftime '%Y%m%d%H%M%S'
|
16
|
-
else
|
17
|
-
"%.3d" % ( current_migration_number(dirname) + 1 )
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_initializer
|
22
|
-
template 'initializer.rb', 'config/initializers/notification-settings.rb'
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_notifications_migration_file
|
26
|
-
migration_template 'notifications_migration.rb.erb', 'db/migrate/notification_settings_migration.rb', migration_version: migration_version
|
27
|
-
end
|
28
|
-
|
29
|
-
def show_readme
|
30
|
-
readme 'README.md'
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def migration_version
|
36
|
-
if Rails.version >= '5.0.0'
|
37
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Now run `rails db:migrate` to add NotificationSettings to your database.
|
@@ -1,24 +0,0 @@
|
|
1
|
-
NotificationSettings.configure do |config|
|
2
|
-
|
3
|
-
# Choose your default notification category. Takes a string.
|
4
|
-
# config.default_category = 'notification'
|
5
|
-
|
6
|
-
|
7
|
-
### STATUS ###
|
8
|
-
|
9
|
-
# Time duration without activity after which the status defaults to `'idle'`. Takes a time.
|
10
|
-
# config.idle_after = 10.minutes
|
11
|
-
|
12
|
-
# Time duration without activity after which the status defaults to `'offline'`. Takes a time.
|
13
|
-
# config.offline_after = 3.hours
|
14
|
-
|
15
|
-
# Stringified datetime attribute name of `object` that defines the time of the last activity. Takes a string.
|
16
|
-
# config.last_seen = 'last_seen'
|
17
|
-
|
18
|
-
# Array of possible statuses that will prevent creating notifications for a target. Takes an array of strings.
|
19
|
-
# config.do_not_notify_statuses = []
|
20
|
-
|
21
|
-
# Array of possible statuses that will prevent pushing notifications of a target. Takes an array of strings.
|
22
|
-
# config.do_not_push_statuses = ['do not disturb']
|
23
|
-
|
24
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class NotificationSettingsMigration < ActiveRecord::Migration<%= migration_version %>
|
2
|
-
def change
|
3
|
-
add_column :notifications, :subscription_id, :bigint, index: true
|
4
|
-
add_column :notifications, :category, :string, index: true
|
5
|
-
|
6
|
-
create_table :notification_settings_settings do |t|
|
7
|
-
|
8
|
-
t.references :object, polymorphic: true, index: { name: 'idx_settings_object_type_object_id' }
|
9
|
-
t.references :subscription, index: true
|
10
|
-
|
11
|
-
t.string :status
|
12
|
-
|
13
|
-
t.text :settings
|
14
|
-
t.text :category_settings
|
15
|
-
|
16
|
-
t.timestamps
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
create_table :notification_settings_subscriptions do |t|
|
21
|
-
|
22
|
-
t.references :subscriber, polymorphic: true, index: { name: 'idx_subscriptions_subscriber_type_subscriber_id' }
|
23
|
-
t.references :subscribable, polymorphic: true, index: { name: 'idx_subscriptions_subscribable_type_subscribable_id' }
|
24
|
-
|
25
|
-
t.timestamps
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module NotificationSettings
|
2
|
-
|
3
|
-
require 'notification_settings/configuration'
|
4
|
-
|
5
|
-
require 'notification_settings/engine'
|
6
|
-
|
7
|
-
autoload :Target, 'notification_settings/target'
|
8
|
-
autoload :Subscriber, 'notification_settings/subscriber'
|
9
|
-
autoload :Subscribable, 'notification_settings/subscribable'
|
10
|
-
autoload :SettingLibrary, 'notification_settings/setting_library'
|
11
|
-
autoload :SubscriptionLibrary, 'notification_settings/subscription_library'
|
12
|
-
autoload :NotificationLibrary, 'notification_settings/notification_library'
|
13
|
-
autoload :NotificationScopes, 'notification_settings/notification_scopes'
|
14
|
-
|
15
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module NotificationSettings
|
2
|
-
|
3
|
-
class << self
|
4
|
-
attr_accessor :configuration
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.configure
|
8
|
-
self.configuration ||= Configuration.new
|
9
|
-
yield configuration
|
10
|
-
end
|
11
|
-
|
12
|
-
class Configuration
|
13
|
-
|
14
|
-
attr_accessor :default_category
|
15
|
-
attr_accessor :last_seen
|
16
|
-
attr_accessor :idle_after
|
17
|
-
attr_accessor :offline_after
|
18
|
-
attr_accessor :do_not_notify_statuses
|
19
|
-
attr_accessor :do_not_push_statuses
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
@default_category = 'notification'
|
23
|
-
@last_seen = 'last_seen'
|
24
|
-
@idle_after = 10.minutes
|
25
|
-
@offline_after = 3.hours
|
26
|
-
@do_not_notify_statuses = []
|
27
|
-
@do_not_push_statuses = ['do not disturb']
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'notification-handler'
|
2
|
-
require 'active_support'
|
3
|
-
|
4
|
-
module NotificationSettings
|
5
|
-
module NotificationLibrary
|
6
|
-
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
before_create :validate_create
|
11
|
-
belongs_to :subscription, class_name: 'NotificationSettings::Subscription', optional: true
|
12
|
-
|
13
|
-
include NotificationSettings::NotificationLibrary::InstanceMethods
|
14
|
-
end
|
15
|
-
|
16
|
-
module InstanceMethods
|
17
|
-
|
18
|
-
def category
|
19
|
-
self[:category] || NotificationRenderer.configuration.default_category
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def validate_create
|
25
|
-
valid = true
|
26
|
-
|
27
|
-
if self.target.notification_setting.present?
|
28
|
-
# Status
|
29
|
-
valid = false if NotificationSettings.configuration.do_not_notify_statuses.include?(self.target.notification_setting.status)
|
30
|
-
|
31
|
-
# Settings
|
32
|
-
valid = false if !self.target.notification_setting.settings.dig(:enabled)
|
33
|
-
## Category
|
34
|
-
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, :enabled)
|
35
|
-
end
|
36
|
-
|
37
|
-
valid
|
38
|
-
end
|
39
|
-
|
40
|
-
def validate_push
|
41
|
-
valid = true
|
42
|
-
|
43
|
-
if self.target.notification_setting.present?
|
44
|
-
# Status
|
45
|
-
valid = false if NotificationSettings.configuration.do_not_push_statuses.include?(self.target.notification_setting.status)
|
46
|
-
|
47
|
-
# Settings
|
48
|
-
if self.push.kind_of?(Array)
|
49
|
-
self.push.each do |pusher|
|
50
|
-
valid = false if !self.target.notification_setting.settings.dig(pusher.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(pusher.to_sym).nil? )
|
51
|
-
## Category
|
52
|
-
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, pusher.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, pusher.to_sym).nil? )
|
53
|
-
end
|
54
|
-
else
|
55
|
-
valid = false if !self.target.notification_setting.settings.dig(self.push.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(self.push.to_sym).nil? )
|
56
|
-
## Category
|
57
|
-
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym).nil? )
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
valid
|
62
|
-
end
|
63
|
-
|
64
|
-
def initialize_pusher
|
65
|
-
return unless validate_push
|
66
|
-
super
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'notification-handler'
|
2
|
-
require 'active_support'
|
3
|
-
|
4
|
-
module NotificationSettings
|
5
|
-
module NotificationScopes
|
6
|
-
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
include NotificationSettings::NotificationScopes::InstanceMethods
|
11
|
-
end
|
12
|
-
|
13
|
-
module InstanceMethods
|
14
|
-
|
15
|
-
def method_missing m, *args
|
16
|
-
if m.to_s[/(.+)_category/]
|
17
|
-
where category: $1.singularize.classify
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def respond_to? m, include_private = false
|
24
|
-
super || m.to_s[/(.+)_category/]
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module NotificationSettings
|
4
|
-
module SettingLibrary
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
include NotificationSettings::SettingLibrary::InstanceMethods
|
10
|
-
end
|
11
|
-
|
12
|
-
module InstanceMethods
|
13
|
-
|
14
|
-
def status
|
15
|
-
if self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.idle_after && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round < NotificationSettings.configuration.offline_after
|
16
|
-
default = 'idle'
|
17
|
-
elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after
|
18
|
-
default = 'offline'
|
19
|
-
else
|
20
|
-
'online'
|
21
|
-
end
|
22
|
-
self[:status] || default
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module NotificationSettings
|
4
|
-
module Subscribable
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
has_many :notification_subscriptions, as: :subscribable, class_name: 'NotificationSettings::Subscription', dependent: :destroy
|
10
|
-
has_many :notification_subscribers, through: :notification_subscriptions, source: :subscriber
|
11
|
-
|
12
|
-
include NotificationSettings::Subscribable::InstanceMethods
|
13
|
-
end
|
14
|
-
|
15
|
-
module InstanceMethods
|
16
|
-
|
17
|
-
def notify_subscribers options = {}
|
18
|
-
options[:object] = self
|
19
|
-
subscribers = notify_dependents options.delete(:dependents)
|
20
|
-
self.notification_subscribers&.each { |subscriber| subscribers << subscriber }
|
21
|
-
subscribers.to_a.uniq&.each do |subscriber|
|
22
|
-
subscriber.notify options
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def notify_dependents dependents
|
27
|
-
subscribers = []
|
28
|
-
dependents ||= self.notification_dependents
|
29
|
-
dependents&.each { |dependent| dependent.notification_subscribers&.each { |subscriber| subscribers << subscriber } }
|
30
|
-
subscribers
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def notification_dependents
|
36
|
-
[]
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module NotificationSettings
|
4
|
-
module Subscriber
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
has_many :notification_subscriptions, as: :subscriber, class_name: 'NotificationSettings::Subscription', dependent: :destroy
|
10
|
-
has_many :notification_subscribables, through: :notification_subscriptions, source: :subscribable
|
11
|
-
|
12
|
-
include NotificationSettings::Subscriber::InstanceMethods
|
13
|
-
end
|
14
|
-
|
15
|
-
module InstanceMethods
|
16
|
-
|
17
|
-
def subscribe subscribable, options = {}
|
18
|
-
options[:subscribable] = subscribable
|
19
|
-
self.notification_subscriptions.create options
|
20
|
-
end
|
21
|
-
|
22
|
-
def unsubscribe subscribable
|
23
|
-
subscription = self.notification_subscriptions.find_by subscribable_id: subscribable.id, subscribable_type: subscribable.class.name
|
24
|
-
subscription.destroy
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module NotificationSettings
|
4
|
-
module SubscriptionLibrary
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
after_create_commit :create_notification_setting
|
10
|
-
|
11
|
-
include NotificationSettings::SubscriptionLibrary::InstanceMethods
|
12
|
-
end
|
13
|
-
|
14
|
-
module InstanceMethods
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def create_notification_setting
|
19
|
-
self.notification_setting.create!
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module NotificationSettings
|
4
|
-
module Target
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
has_one :notification_setting, as: :object, class_name: 'NotificationSettings::Setting', dependent: :destroy
|
10
|
-
before_create :create_notification_setting
|
11
|
-
|
12
|
-
include NotificationSettings::Target::InstanceMethods
|
13
|
-
end
|
14
|
-
|
15
|
-
module InstanceMethods
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def create_notification_setting
|
20
|
-
self.build_notification_setting
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|