Module: AbstractNotifier

Defined in:
lib/abstract_notifier.rb,
lib/abstract_notifier/base.rb,
lib/abstract_notifier/testing.rb,
lib/abstract_notifier/version.rb,
lib/abstract_notifier/testing/rspec.rb,
lib/abstract_notifier/async_adapters.rb,
lib/abstract_notifier/async_adapters/active_job.rb

Overview

Abstract Notifier is responsible for generating and triggering text-based notifications (like Action Mailer for email notifications).

Example:

class ApplicationNotifier < AbstractNotifier::Base
  self.driver = NotifyService.new

  def profile
    params[:profile] if params
  end
end

class EventsNotifier < ApplicationNotifier
  def canceled(event)
    notification(
      # the only required option is `body`
      body: "Event #{event.title} has been canceled",
      # all other options are passed to delivery driver
      identity: profile.notification_service_id
    )
 end
end

EventsNotifier.with(profile: profile).canceled(event).notify_later

Defined Under Namespace

Modules: AsyncAdapters, Testing Classes: Base, HaveEnqueuedNotification, HaveSentNotification, Notification

Constant Summary collapse

DELIVERY_MODES =
i[test noop normal].freeze
VERSION =
"0.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.async_adapterObject

Returns the value of attribute async_adapter.



36
37
38
# File 'lib/abstract_notifier.rb', line 36

def async_adapter
  @async_adapter
end

.delivery_modeObject

Returns the value of attribute delivery_mode.



35
36
37
# File 'lib/abstract_notifier.rb', line 35

def delivery_mode
  @delivery_mode
end

Class Method Details

.noop?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/abstract_notifier.rb', line 52

def noop?
  delivery_mode == :noop
end

.test?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/abstract_notifier.rb', line 56

def test?
  delivery_mode == :test
end