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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5972f18fd90453803b464904b668bd3f908ed01e51acd07d3a20e498dcc8e956
4
- data.tar.gz: fbaeced3b28d810bd5b9ff449eb6a021e61402f5223f5c1c372ecaa94f5d99ff
3
+ metadata.gz: 5f50994ef8bb3ce66b26f1b4a84ccdd4805a53988895f0b22f78ce29bf467740
4
+ data.tar.gz: ce5b76bed74ddde7ab136bfc691a915fc71d03c7e74b1bc06eefcd829b9e88f1
5
5
  SHA512:
6
- metadata.gz: 579f407fb64d82aa9401a23a591003a5016fbdbdaf0aa66e1967c6b6167adb09513d66d2cd46696ff1463ce65eb7b900c41c78963a4f7f8a8d1b61e284e927d8
7
- data.tar.gz: ea64460d759b552f28977a566d1048d38524ee57b6f749dd6cb5c6526277436cb61a54b5fb70c62c40853cf040b0daac7d9bfa1b3c3eaed1f36f92760b3b1316
6
+ metadata.gz: 32208d0bde61260f3451de68d9030f412d9c96988ac6a7d2c679e96d6a4ff6649ccf01f79eea016344cfc6baadd5dc2b2a11ac928a7a9b1af957b05a7b70bc7a
7
+ data.tar.gz: 83740047beef8a0eb660f970daa45b64f0d4f5bee16213d7c7b3687e5b9636f57d35222bc59363db7963fc60cd6d4c912a59216cac0f2d62010c27b575657bfc
@@ -4,6 +4,13 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 1.2.0 - 2018-01-02
8
+
9
+ * features
10
+ * added dependents functionality to subscribers feature
11
+ * bugfixes
12
+ * fixed `uninitialized constant NotificationSettings::Object`
13
+
7
14
  ### 1.1.2 - 2018-01-01
8
15
 
9
16
  * bugfixes
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
- self.notification_subscribers.each do |subscriber|
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.1.2
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.1.2
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.1.2
68
+ version: 1.2.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement