noticed 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/noticed/base.rb +22 -14
- data/lib/noticed/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a50bd43b89379867d1a76114bf3d306a9f7bb983e87ba9d8c293b34c5ed5fe7f
|
4
|
+
data.tar.gz: 2ac5422b2de7a9b4a7cde0ceddb2fb89eef13ed641fba3d4bff2d251a34fbfba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856584e1f6045ca6db3badc0611066fcb709754008ec28806b4cf56b6be1f5ad62d7f6e8ee47ee181b446c19af1080e6352e2b551a8adf65e51a4d05e25d1c22
|
7
|
+
data.tar.gz: 2f4b8aa9183bbca49af5228f309a48448ffda1abf5ad302b405c1cafb43b82039a25b485c8d59dab4fdfe69242f247867cbdc6d4dad6fb21d7e4f09a7e1c015e
|
data/README.md
CHANGED
@@ -81,6 +81,9 @@ notification.deliver_later(@comment.post.author)
|
|
81
81
|
|
82
82
|
# Deliver notification immediately
|
83
83
|
notification.deliver(@comment.post.author)
|
84
|
+
|
85
|
+
# Deliver notification to multiple recipients
|
86
|
+
notification.deliver_later(User.all)
|
84
87
|
```
|
85
88
|
|
86
89
|
This will instantiate a new notification with the `comment` stored in the notification's params.
|
@@ -153,8 +156,6 @@ class CommentNotification < Noticed::Base
|
|
153
156
|
end
|
154
157
|
```
|
155
158
|
|
156
|
-
###
|
157
|
-
|
158
159
|
## 🚛 Delivery Methods
|
159
160
|
|
160
161
|
The delivery methods are designed to be modular so you can customize the way each type gets delivered.
|
data/lib/noticed/base.rb
CHANGED
@@ -37,14 +37,24 @@ module Noticed
|
|
37
37
|
@params = params
|
38
38
|
end
|
39
39
|
|
40
|
-
def deliver(
|
40
|
+
def deliver(recipients)
|
41
41
|
validate!
|
42
|
-
|
42
|
+
|
43
|
+
run_callbacks :deliver do
|
44
|
+
Array.wrap(recipients).each do |recipient|
|
45
|
+
run_delivery(recipient, enqueue: false)
|
46
|
+
end
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
|
-
def deliver_later(
|
50
|
+
def deliver_later(recipients)
|
46
51
|
validate!
|
47
|
-
|
52
|
+
|
53
|
+
run_callbacks :deliver do
|
54
|
+
Array.wrap(recipients).each do |recipient|
|
55
|
+
run_delivery(recipient, enqueue: true)
|
56
|
+
end
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
60
|
def params
|
@@ -55,18 +65,16 @@ module Noticed
|
|
55
65
|
|
56
66
|
# Runs all delivery methods for a notification
|
57
67
|
def run_delivery(recipient, enqueue: true)
|
58
|
-
|
59
|
-
delivery_methods = self.class.delivery_methods.dup
|
68
|
+
delivery_methods = self.class.delivery_methods.dup
|
60
69
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
# Run database delivery inline first if it exists so other methods have access to the record
|
71
|
+
if (index = delivery_methods.find_index { |m| m[:name] == :database })
|
72
|
+
delivery_method = delivery_methods.delete_at(index)
|
73
|
+
@record = run_delivery_method(delivery_method, recipient: recipient, enqueue: false)
|
74
|
+
end
|
66
75
|
|
67
|
-
|
68
|
-
|
69
|
-
end
|
76
|
+
delivery_methods.each do |delivery_method|
|
77
|
+
run_delivery_method(delivery_method, recipient: recipient, enqueue: enqueue)
|
70
78
|
end
|
71
79
|
end
|
72
80
|
|
data/lib/noticed/version.rb
CHANGED