Sha256: 28e6db402264bd5b9cef953c8e67cce9b4fafe5b0bd2d2bc087ee75db3a8ec59

Contents?: true

Size: 980 Bytes

Versions: 2

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

module NotificationPusher
  module DeliveryMethod
    class ActionMailer < NotificationPusher::DeliveryMethod::Base
      require_relative 'action_mailer/engine'

      DEFAULT_MAILER_ACTION = :push
      DEFAULT_DELIVER_METHOD = :deliver

      def call
        mailer_class.send(mailer_action, notification, options)
                    .send(deliver_method)
      end

      private

      def mailer_class
        return options[:mailer] if options.key?(:mailer)
        if defined?(NotificationRenderer)
          return ::NotificationPusher::ActionMailer::NotificationMailer
        end

        raise(ArgumentError,
              'You have to pass the :mailer option explicitly or require ' \
              "'notification-renderer'")
      end

      def mailer_action
        options[:action] || DEFAULT_MAILER_ACTION
      end

      def deliver_method
        options[:deliver_method] || DEFAULT_DELIVER_METHOD
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notification-pusher-actionmailer-3.0.2 lib/notification_pusher/delivery_method/action_mailer.rb
notification-pusher-actionmailer-2.0.0 lib/notification_pusher/delivery_method/action_mailer.rb