Sha256: 5fb990022e6292b00efa5b0edbb8cf539dea3934c11daf46b0a8686f1357e1cd

Contents?: true

Size: 988 Bytes

Versions: 5

Compression:

Stored size: 988 Bytes

Contents

module Wupee
  class NotificationsMailer < ActionMailer::Base
    after_action :mark_notification_as_sent

    def send_mail_for(notification, subject_interpolations = {})
      @notification = notification
      @receiver = notification.receiver
      @attached_object = notification.attached_object
      @subject_interpolations = subject_interpolations

      if !respond_to?(notification.notification_type.name)
        class_eval %Q{
          def #{notification.notification_type.name}
            mail to: @receiver.email,
                 subject: t('wupee.email_subjects.#{notification.notification_type.name}', @subject_interpolations),
                 template_name: '#{notification.notification_type.name}',
                 content_type: 'text/html'
          end
        }
      end

      send(notification.notification_type.name)
    end

    private
      def mark_notification_as_sent
        @notification.mark_as_sent unless @notification.is_sent
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wupee-1.0.4 app/mailers/wupee/notifications_mailer.rb
wupee-1.0.3 app/mailers/wupee/notifications_mailer.rb
wupee-1.0.2 app/mailers/wupee/notifications_mailer.rb
wupee-1.0.1 app/mailers/wupee/notifications_mailer.rb
wupee-1.0.0 app/mailers/wupee/notifications_mailer.rb