Add notification_methods for adding methods to the Notification model #362
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces a
notification_methods
block for Notifiers to add methods to the Noticed::Notification records. This works by adding STI to Noticed::Notifications, dynamically creating a Notification class for each Notifier and applying methods to it.Without this feature, it is tricky to load notifications from the database and call methods on the Notifier that require the
notification
orrecipient
:While this is fine, it feels incomplete.
By introducing
notification_methods
, we can refactor the above to this:This is considerably cleaner and provides a handy way of extending the Notification class while also making the methods unique to each Notifier. If we added the
message
method toNoticed::Notification
directly, it would share that method across all Notifiers.See #360 for the discussion leading to this.