noticed 1.5.9 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 367ce1b20a44bfc15ebf8aeaa0328ef90ad0673edd076e977d0e647a3a1b13b7
4
- data.tar.gz: 437627e876b7e42243626bab168b9fd37d7da49c54309e2f8f9ef91dfb5e541b
3
+ metadata.gz: eade1cdb53653ae77fa61a1348340402ea37625188677a16baddda26bc42bd49
4
+ data.tar.gz: 11d1d9ba60517005306714fc028fd312bbee7bef489d19218e7ba5c6938e22eb
5
5
  SHA512:
6
- metadata.gz: 5991aa837054391b01f5614617db15951279d4015c96eab52194ad7a0ab05cf3d586353cb5968bb04584246b23682c75365858464062c852b70f9553f0be8ad5
7
- data.tar.gz: ff4adba6ae61a08bf8dab9a4b27899c3e5dd3dea8e1475fa7f1da589db85ce17b264d02ed523ea38d905bd53016f2e1d483cf4a7c18ea9461e1b12ef056868e6
6
+ metadata.gz: '08b57a6181fa23484fa7c21eb7153a75c2bb05750532d2c649a8bc46e30b57be8041039802396167e639fede5595c64bb09d683eaeb1f23a0b0d346f2e76ca5e'
7
+ data.tar.gz: cc01ee47a638c02f1e5311c1433735607052130be9b4beaf61ced7482fd31910ab8c8a17915ff9c60a50bccddbc86bcb14f44519d8119632a95a1eba214f22a4
data/README.md CHANGED
@@ -194,6 +194,8 @@ deliver_by :slack, debug: true
194
194
 
195
195
  ## ✅ Best Practices
196
196
 
197
+ ### Creating a notification from an Active Record callback
198
+
197
199
  A common use case is to trigger a notification when a record is created. For example,
198
200
 
199
201
  ```ruby
@@ -217,6 +219,23 @@ A common symptom of this problem is undelivered notifications and the following
217
219
 
218
220
  > `Discarded Noticed::DeliveryMethods::Email due to a ActiveJob::DeserializationError.`
219
221
 
222
+ ### Renaming notifications
223
+
224
+ If you rename the class of a notification object your existing queries can break. This is because Noticed serializes the class name and sets it to the `type` column on the `Notification` record.
225
+
226
+ You can catch these errors at runtime by using `YourNotificationClassName.name` instead of hardcoding the string when performing a query.
227
+
228
+ ```ruby
229
+ Notification.where(type: YourNotificationClassName.name) # good
230
+ Notification.where(type: "YourNotificationClassName") # bad
231
+ ```
232
+
233
+ When renaming a notification class you will need to backfill existing notifications to reference the new name.
234
+
235
+ ```ruby
236
+ Notification.where(type: "OldNotificationClassName").update_all(type: NewNotificationClassName.name)
237
+ ```
238
+
220
239
  ## 🚛 Delivery Methods
221
240
 
222
241
  The delivery methods are designed to be modular so you can customize the way each type gets delivered.
@@ -351,22 +370,6 @@ class DeliveryMethods::Discord < Noticed::DeliveryMethods::Base
351
370
  end
352
371
  ```
353
372
 
354
- #### Limitations
355
-
356
- Rails 6.1+ can serialize Class and Module objects as arguments to ActiveJob. The following syntax should work for Rails 6.1+:
357
-
358
- ```ruby
359
- deliver_by DeliveryMethods::Discord
360
- ```
361
-
362
- For Rails 5.2 and 6.0, you must pass strings of the class names in the `deliver_by` options.
363
-
364
- ```ruby
365
- deliver_by :discord, class: "DeliveryMethods::Discord"
366
- ```
367
-
368
- We recommend using a string in order to prevent confusion.
369
-
370
373
  ### 📦 Database Model
371
374
 
372
375
  The Notification database model includes several helpful features to make working with database notifications easier.
@@ -3,5 +3,5 @@
3
3
 
4
4
  Next steps:
5
5
  1. Run "rails db:migrate"
6
- 2. Add "has_many :notifications, as: :recipient" to your User model(s).
6
+ 2. Add "has_many :notifications, as: :recipient, dependent: :destroy" to your User model(s).
7
7
  3. Generate notifications with "rails g noticed:notification"
data/lib/noticed/base.rb CHANGED
@@ -75,6 +75,10 @@ module Noticed
75
75
  @params || {}
76
76
  end
77
77
 
78
+ def clear_recipient
79
+ self.recipient = nil
80
+ end
81
+
78
82
  private
79
83
 
80
84
  # Runs all delivery methods for a notification
data/lib/noticed/coder.rb CHANGED
@@ -3,6 +3,8 @@ module Noticed
3
3
  def self.load(data)
4
4
  return if data.nil?
5
5
  ActiveJob::Arguments.send(:deserialize_argument, data)
6
+ rescue ActiveRecord::RecordNotFound => error
7
+ {noticed_error: error.message, original_params: data}
6
8
  end
7
9
 
8
10
  def self.dump(data)
data/lib/noticed/model.rb CHANGED
@@ -72,5 +72,10 @@ module Noticed
72
72
  def read?
73
73
  read_at?
74
74
  end
75
+
76
+ # If a GlobalID record in params is no longer found, the params will default with a noticed_error key
77
+ def deserialize_error?
78
+ !!params[:noticed_error]
79
+ end
75
80
  end
76
81
  end
@@ -1,3 +1,3 @@
1
1
  module Noticed
2
- VERSION = "1.5.9"
2
+ VERSION = "1.6.0"
3
3
  end
data/lib/noticed.rb CHANGED
@@ -16,22 +16,13 @@ module Noticed
16
16
  autoload :Base, "noticed/delivery_methods/base"
17
17
  autoload :Database, "noticed/delivery_methods/database"
18
18
  autoload :Email, "noticed/delivery_methods/email"
19
+ autoload :Fcm, "noticed/delivery_methods/fcm"
19
20
  autoload :Ios, "noticed/delivery_methods/ios"
20
21
  autoload :MicrosoftTeams, "noticed/delivery_methods/microsoft_teams"
21
22
  autoload :Slack, "noticed/delivery_methods/slack"
22
23
  autoload :Test, "noticed/delivery_methods/test"
23
24
  autoload :Twilio, "noticed/delivery_methods/twilio"
24
25
  autoload :Vonage, "noticed/delivery_methods/vonage"
25
- autoload :Fcm, "noticed/delivery_methods/fcm"
26
- end
27
-
28
- def self.notify(recipients:, notification:)
29
- recipients.each do |recipient|
30
- notification.notify(recipient)
31
- end
32
-
33
- # Clear the recipient after sending to the group
34
- notification.recipient = nil
35
26
  end
36
27
 
37
28
  mattr_accessor :parent_class
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.5.9
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubygems_version: 3.3.3
173
+ rubygems_version: 3.3.7
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Notifications for Ruby on Rails applications