Skip to content

The Notification Object

Sean C Davis edited this page Sep 5, 2016 · 1 revision

The NotifyOn::Notification class is tucked away in the gem so you don't have to worry about it. But it'd be nice to know what you can do with it, right?

Associations

Associations on a notification object are generally eager loaded. They are:

  • recipient is the object that received the notification (to)
  • sender is the object that sent the notification (from)
  • trigger is the object that triggered the notification (the model where you called notify_on)

Attributes

There are a few attributes that a notification resolves for you:

General

  • description: the interpolated description (message). See String Interpolation.
  • link: the resolved reference link (link). See Dynamic Link Generator.
  • unread: whether or not the notification has been read. It is set to false by default when you a notification is created.
  • options: a Hash of the options you passed to notify_on. (Hint: Using opts instead of options returns a Hashie::Mash object, which can be easier to work with.)

Email

Email settings are resolved via the combination of NotifyOn's default settings, your settings from config/intitializers/notify_on.rb and the notification's individual options.

  • email_template: name of the email template to use
  • email_from: email address that sent the notification
  • email_subject: subject of the email message

Pusher

Pushere settings are resolved via the combination of NotifyOn's default settings, your settings from config/intitializers/notify_on.rb and the notification's individual options.

  • pusher_sender_active?: if the notification sender is present in the Pusher channel the notification was sent to.
  • pusher_recipient_active?: if the notification recipient is present in the Pusher channel the notification was sent to.
  • pusher_channel_name: name of the channel to send the Pusher notification
  • pusher_event_name: name of the notification's Pusher event
  • pusher_attrs: a Hash including the trigger and notification, along with any custom options you set

Actions

You can alter the notification with the following:

  • read! will set unread to false.
  • push! will send the push notification via Pusher, but all the appropriate options must be in place.
  • send_email will send the email message if the appropriate options are in place.