diff --git a/README.md b/README.md index 0f3fbdc..f3924f2 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Noticed operates with a few constructs: Notifiers, delivery methods, and Notific To start, generate a Notifier: -```sh +```bash rails generate noticed:notifier NewCommentNotifier ``` @@ -202,12 +202,12 @@ class CommentNotifier < Noticed::Event end end -class Recipent < ApplicationRecord # or whatever your recipient model is +class Recipient < ApplicationRecord # or whatever your recipient model is has_many :ios_device_tokens - def send_ios_notification? - # some logic - end + def send_ios_notification? + # some logic + end end ``` @@ -297,9 +297,9 @@ Will look for the following translation path: en: notifiers: - new_comment_notifier: - notification: - message: "Someone posted a new comment!" + new_comment_notifier: + notification: + message: "Someone posted a new comment!" ``` Or, if you have your Notifier within another module, such as `Admin::NewCommentNotifier`, the resulting lookup path will be `en.notifiers.admin.new_comment_notifier.notification.message` (modules become nesting steps). @@ -361,8 +361,8 @@ Each of these options are available for every delivery method (individual or bul * `config.if` — Intended for a lambda or method; runs after the `wait` if configured; cancels the delivery method if returns falsey * `config.unless` — Intended for a lambda or method; runs after the `wait` if configured; cancels the delivery method if returns truthy * `config.wait` — (Should yield an `ActiveSupport::Duration`) Delays the job that runs this delivery method for the given duration of time -* `config.wait_until` — (Should yield a specific time object) Delays the job that runs this delivery method until the specific time specified -* `config.queue` — Sets the ActiveJob queue name to be used for the job that runs this delivery method +* `config.wait_until` — (Should yield a specific time object) Delays the job that runs this delivery method until the specific time specified +* `config.queue` — Sets the ActiveJob queue name to be used for the job that runs this delivery method ### 📨 Sending Notifications @@ -489,7 +489,7 @@ Sending a notification is entirely an internal-to-your-app function. Delivery me A common pattern is to deliver a notification via a real (or real-ish)-time service, 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 `wait` option, and the conditional `if` / `unless` option. ```ruby -class NewCommentNotifier< Noticed::Event +class NewCommentNotifier < Noticed::Event deliver_by :action_cable deliver_by :email do |config| config.mailer = "CommentMailer" @@ -544,6 +544,7 @@ See the [Custom Noticed Model Methods](#custom-noticed-model-methods) section fo ```ruby # app/notifiers/delivery_methods/turbo_stream.rb + class DeliveryMethods::TurboStream < ApplicationDeliveryMethod def deliver return unless recipient.is_a?(User) @@ -557,6 +558,7 @@ end ```ruby # app/models/concerns/noticed/notification_extensions.rb + module Noticed::NotificationExtensions extend ActiveSupport::Concern @@ -592,12 +594,12 @@ end Delivery methods have access to the following methods and attributes: -* `event` — The `Noticed::Event` record that spawned the notification object currently being delivered -* `record` — The object originally passed into the Notifier as the `record:` param (see the ✨ note above) -* `notification` — The `Noticed::Notification` instance being delivered. All notification helper methods are available on this object -* `recipient` — The individual recipient object being delivered to for this notification (remember that each recipient gets their own instance of the Delivery Method `#deliver`) -* `config` — The hash of configuration options declared by the Notifier that generated this notification and delivery -* `params` — The parameters given to the Notifier in the invocation (via `.with()`) +* `event` — The `Noticed::Event` record that spawned the notification object currently being delivered +* `record` — The object originally passed into the Notifier as the `record:` param (see the ✨ note above) +* `notification` — The `Noticed::Notification` instance being delivered. All notification helper methods are available on this object +* `recipient` — The individual recipient object being delivered to for this notification (remember that each recipient gets their own instance of the Delivery Method `#deliver`) +* `config` — The hash of configuration options declared by the Notifier that generated this notification and delivery +* `params` — The parameters given to the Notifier in the invocation (via `.with()`) #### Validating config options passed to Custom Delivery methods @@ -628,7 +630,7 @@ class DeliveryMethods::WhatsApp < Noticed::DeliveryMethod def deliver # ... - config.day #=> # + config.day #=> # evaluate_option(config.day) #=> "Tuesday" end end @@ -803,4 +805,5 @@ DATABASE_URL=postgres://127.0.0.1/noticed_test rails test ``` ## 📝 License + The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).