noticed 1.2.20 → 1.2.21

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: e5b998072ed72c9844842d8610a9ffcea75cf16f958296aa3d53e1a3c050b6db
4
- data.tar.gz: 589f43985b3dc7740977730d10917d0b111706fe56c4daafedbacc08e7f2ce84
3
+ metadata.gz: e648889dba7414cf25efd56b6b39aeeef03c44febfd7bbfccf47151cb940736e
4
+ data.tar.gz: 0ecb213d7913181f686bbd5cd716e617f0cb6da58a87a4c3185d8e69dcf114c0
5
5
  SHA512:
6
- metadata.gz: 9f4a336ed688008a5abc3f91099a5ecc4128361beffd216e0e2e0bc0a1670286e607577d2f4ce13f1e36c2fb2fff3d93fbab9a10914d0321a2d1e0c2449ea715
7
- data.tar.gz: b4a67b79dcf34892dcd11b56ad83e2c393a2da49c3eb38e3e911411164b4150ec27a836e53d1d7875ea40141276a398878e8c23304c326287299b26bafebacba
6
+ metadata.gz: 65a6fdd5fa8ea6cea59201358b62a93c5b98af509d8edd0694afda809887367baf973173ecc1bf401e54cb9dc0700989cb7e6e8ff56aa0978b130a8c10b2250b
7
+ data.tar.gz: e873f202212c36f16b2a97ab7fc678498ded0383bc2ac0ca1af9c647806c0c827be8c85833199af34823202bb8b029fffd66d60903928377890bbcd1e0b4209f
data/README.md CHANGED
@@ -354,6 +354,33 @@ Sends an SMS notification via Vonage / Nexmo.
354
354
  }
355
355
  ```
356
356
 
357
+ ### Fallback Notifications
358
+
359
+ A common pattern is to deliver a notification via the database and then, after some time has passed, email the user if they have not yet read the notification. You can implement this functionality by combining multiple delivery methods, the `delay` option, and the conditional `if` / `unless` option.
360
+
361
+ ```ruby
362
+ class CommentNotification < Noticed::Base
363
+ deliver_by :database
364
+ deliver_by :email, mailer: 'CommentMailer', delay: 15.minutes, unless: :read?
365
+ end
366
+ ```
367
+
368
+ Here a notification will be created immediately in the database (for display directly in your app). If the notification has not been read after 15 minutes, the email notification will be sent. If the notification has already been read in the app, the email will be skipped.
369
+
370
+ You can also configure multiple fallback options:
371
+
372
+ ```ruby
373
+ class CriticalSystemNotification < Noticed::Base
374
+ deliver_by :slack
375
+ deliver_by :email, mailer: 'CriticalSystemMailer', delay: 10.minutes, unless: :read?
376
+ deliver_by :twilio, delay: 20.minutes, unless: :read?
377
+ end
378
+ ```
379
+
380
+ In this scenario, you can create an escalating notification that starts with a ping in Slack, then emails the team, and then finally sends an SMS to the on-call phone.
381
+
382
+ You can mix and match the options and delivery methods to suit your application specific needs.
383
+
357
384
  ### 🚚 Custom Delivery Methods
358
385
 
359
386
  To generate a custom delivery method, simply run
@@ -12,6 +12,8 @@ module Noticed
12
12
  # Gives notifications access to the record and recipient when formatting for delivery
13
13
  attr_accessor :record, :recipient
14
14
 
15
+ delegate :read?, :unread?, to: :record
16
+
15
17
  class << self
16
18
  def deliver_by(name, options = {})
17
19
  delivery_methods.push(name: name, options: options)
@@ -18,14 +18,12 @@ module Noticed
18
18
  end
19
19
 
20
20
  def format
21
- if (method = options[:format])
21
+ params = if (method = options[:format])
22
22
  notification.send(method)
23
23
  else
24
- notification.params.merge(
25
- recipient: recipient,
26
- record: record
27
- )
24
+ notification.params
28
25
  end
26
+ params.merge(recipient: recipient, record: record)
29
27
  end
30
28
  end
31
29
  end
@@ -1,3 +1,3 @@
1
1
  module Noticed
2
- VERSION = "1.2.20"
2
+ VERSION = "1.2.21"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noticed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.20
4
+ version: 1.2.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-23 00:00:00.000000000 Z
11
+ date: 2020-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails