Class: Mailboxer::MailDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mailboxer/mail_dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailable, recipients) ⇒ MailDispatcher

Returns a new instance of MailDispatcher


6
7
8
# File 'lib/mailboxer/mail_dispatcher.rb', line 6

def initialize(mailable, recipients)
  @mailable, @recipients = mailable, recipients
end

Instance Attribute Details

#mailableObject (readonly)

Returns the value of attribute mailable


4
5
6
# File 'lib/mailboxer/mail_dispatcher.rb', line 4

def mailable
  @mailable
end

#recipientsObject (readonly)

Returns the value of attribute recipients


4
5
6
# File 'lib/mailboxer/mail_dispatcher.rb', line 4

def recipients
  @recipients
end

Instance Method Details

#callObject


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mailboxer/mail_dispatcher.rb', line 10

def call
  return false unless Mailboxer.uses_emails
  if Mailboxer.mailer_wants_array
    send_email(filtered_recipients)
  else
    filtered_recipients.each do |recipient|
      email_to = recipient.send(Mailboxer.email_method, mailable)
      send_email(recipient) if email_to.present?
    end
  end
end