Class: MandrillMailer::TemplateMailer

Inherits:
CoreMailer
  • Object
show all
Defined in:
lib/mandrill_mailer/offline.rb,
lib/mandrill_mailer/template_mailer.rb

Instance Attribute Summary collapse

Attributes inherited from CoreMailer

#async, #ip_pool, #message, #send_at

Instance Method Summary collapse

Methods inherited from CoreMailer

#bcc, default, #from, #mandrill_mail, super_defaults, test, test_setup_for, #to, #to=

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MandrillMailer::CoreMailer

Instance Attribute Details

#template_contentObject

Public: Template content


118
119
120
# File 'lib/mandrill_mailer/template_mailer.rb', line 118

def template_content
  @template_content
end

#template_nameObject

Public: The name of the template to use


115
116
117
# File 'lib/mandrill_mailer/template_mailer.rb', line 115

def template_name
  @template_name
end

Instance Method Details

#deliverObject

Public: Triggers the stored Mandrill params to be sent to the Mandrill api


121
122
123
# File 'lib/mandrill_mailer/template_mailer.rb', line 121

def deliver
  deliver_now
end

#deliver_later(options = {}) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mandrill_mailer/offline.rb', line 45

def deliver_later
  MandrillMailer::Mock.new({
    :template_name    => template_name,
    :template_content => template_content,
    :message          => message,
    :async            => async,
    :ip_pool          => ip_pool,
    :send_at          => send_at
  }).tap do |mock|
     MandrillMailer.deliveries << mock
  end
end

#deliver_nowObject


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mandrill_mailer/offline.rb', line 33

def deliver_now
  MandrillMailer::Mock.new({
    :template_name    => template_name,
    :template_content => template_content,
    :message          => message,
    :async            => async,
    :ip_pool          => ip_pool,
    :send_at          => send_at
  }).tap do |mock|
     MandrillMailer.deliveries << mock
  end
end

#mandrill_mail_handler(args) ⇒ Object

Handle template mailer specifics before formating the given args


134
135
136
137
138
139
140
141
142
143
# File 'lib/mandrill_mailer/template_mailer.rb', line 134

def mandrill_mail_handler(args)
  # Mandrill requires template content to be there, set default value
  args[:template_content] =  {"blank" => ""} if args[:template_content].blank?

  # Set the template content
  self.template_content = MandrillMailer::ArgFormatter.mandrill_args(args.delete(:template_content))

  # Set the template name
  self.template_name = args.delete(:template)
end