notification-settings 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +23 -0
- data/lib/notification_settings/subscribable.rb +16 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f50994ef8bb3ce66b26f1b4a84ccdd4805a53988895f0b22f78ce29bf467740
|
4
|
+
data.tar.gz: ce5b76bed74ddde7ab136bfc691a915fc71d03c7e74b1bc06eefcd829b9e88f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32208d0bde61260f3451de68d9030f412d9c96988ac6a7d2c679e96d6a4ff6649ccf01f79eea016344cfc6baadd5dc2b2a11ac928a7a9b1af957b05a7b70bc7a
|
7
|
+
data.tar.gz: 83740047beef8a0eb660f970daa45b64f0d4f5bee16213d7c7b3687e5b9636f57d35222bc59363db7963fc60cd6d4c912a59216cac0f2d62010c27b575657bfc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -136,6 +136,29 @@ Now you can easily notify all subscribers from the subscribable object:
|
|
136
136
|
Recipe.first.notify_subscribers push: :ActionMailer
|
137
137
|
```
|
138
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
|
+
|
139
162
|
You can customize settings for a single subscription just as you would for a notification target:
|
140
163
|
|
141
164
|
```ruby
|
@@ -16,11 +16,26 @@ module NotificationSettings
|
|
16
16
|
|
17
17
|
def notify_subscribers options = {}
|
18
18
|
options[:object] = self
|
19
|
-
|
19
|
+
subscribers = notify_dependents options.delete(:dependents)
|
20
|
+
self.notification_subscribers&.each { |subscriber| subscribers << subscriber }
|
21
|
+
subscribers.to_a.uniq&.each do |subscriber|
|
20
22
|
subscriber.notify options
|
21
23
|
end
|
22
24
|
end
|
23
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
|
+
|
24
39
|
end
|
25
40
|
|
26
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.2.0
|
62
62
|
type: :runtime
|
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: 1.
|
68
|
+
version: 1.2.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|