class Mailboxer::MailDispatcher

Attributes

mailable[R]
receipts[R]

Public Class Methods

new(mailable, receipts) click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 5
def initialize(mailable, receipts)
  @mailable, @receipts = mailable, receipts
end

Public Instance Methods

call() click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 9
def call
  return false unless Mailboxer.uses_emails

  receipts.map do |receipt|
    email_to = receipt.receiver.send(Mailboxer.email_method, mailable)
    send_email(receipt) if email_to.present?
  end
end

Private Instance Methods

default_send_email(receipt) click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 46
def default_send_email(receipt)
  mail = mailer.send_email(mailable, receipt.receiver)
  mail.respond_to?(:deliver_now) ? mail.deliver_now : mail.deliver
  receipt.assign_attributes(
    :delivery_method => :email,
    :message_id => mail.message_id
  )
  mail
end
mailer() click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 20
def mailer
  mailer_config_method || mailer_from_mailable || mailer_constant
end
mailer_config_method() click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 28
def mailer_config_method
  klass = mailable.class.name.demodulize
  method = "#{klass.downcase}_mailer".to_sym
  Mailboxer.send(method) if Mailboxer.respond_to? method
end
mailer_constant() click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 34
def mailer_constant
  "#{mailable.class.name}Mailer".constantize
end
mailer_from_mailable() click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 24
def mailer_from_mailable
  mailable.mailer_class if mailable.respond_to? :mailer_class
end
send_email(receipt) click to toggle source
# File lib/mailboxer/mail_dispatcher.rb, line 38
def send_email(receipt)
  if Mailboxer.custom_deliver_proc
    Mailboxer.custom_deliver_proc.call(mailer, mailable, receipt.receiver)
  else
    default_send_email(receipt)
  end
end