class MassMandrill::MandrillMailer

Attributes

message[R]
template_content[R]

Public Class Methods

method_missing(method_name, *args, &block) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 9
def self.method_missing(method_name, *args, &block)
  new(method_name).send(method_name, *args, &block)
end
new(template_name) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 5
def initialize(template_name)
  @template_name = template_name
end

Public Instance Methods

mail(options) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 13
def mail(options)
  @message = build_message(options)
  @template_content = options[:template_content]
  @template_name = options[:template] if options[:template]

  MandrillMail.new(@template_name, @template_content, @message)
end

Private Instance Methods

build_message(options) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 23
def build_message(options)
  {
    :subject => options[:subject],
    :from_email => from_email(options[:from]),
    :from_name => from_name(options[:from]),
    :to => to(options[:to]),
    :preserve_recipients => options[:preserve_recipients],
    :global_merge_vars => options[:global_merge_vars],
    :merge_vars => options[:merge_vars]
  }.merge(options[:message_extra] || {})
end
from_email(from) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 43
def from_email(from)
  scan = scan_email(from)
  scan ? scan.first[1..-2] : from
end
from_name(from) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 48
def from_name(from)
  if scan_email(from)
    from.split(/\</).first.strip
  end
end
scan_email(from) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 54
def scan_email(from)
  from.scan(/\<.*\>/) if from
end
to(addresses) click to toggle source
# File lib/mass_mandrill/mandrill_mailer.rb, line 35
def to(addresses)
  if addresses.is_a?(Array)
    addresses.map { |address| { :email => address } }
  else
    { :email => addresses }
  end
end