From b2f4e3cf9f377b93628497ec0c0bfd77fcef63af Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Tue, 27 Aug 2024 23:04:43 +1000 Subject: [PATCH] Add docs for PR #459 (#482) This adds info about https://github.com/excid3/noticed/pull/459 to the README. --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 2db53fc..23ad63d 100644 --- a/README.md +++ b/README.md @@ -399,6 +399,34 @@ This invocation will create a single `Noticed::Event` record and a `Noticed::Not - An individual delivery job for `:email` method to the second thread author - Etc... +#### Tip: Define recipients inside the notifier + +Recipients can also be computed inside a notifier: + +```ruby +class NewCommentNotifier < ApplicationNotifier + recipients ->{ params[:record].thread.all_authors } + + # or + recipients do + params[:record].thread.all_authors + end + + # or + recipients :fetch_recipients + + def fetch_recipients + # ... + end +end +``` + +This makes the code for sending a notification neater: + +```ruby +NewCommentNotifier.with(record: @comment, foo: "bar").deliver +``` + ### Custom Noticed Model Methods In order to extend the Noticed models you'll need to use a concern and a to_prepare block: