class Forklift::Base::Mailer

Public Class Methods

new(forklift) click to toggle source
# File lib/forklift/base/mailer.rb, line 9
def initialize(forklift)
  @forklift = forklift
end

Public Instance Methods

config() click to toggle source

Public: Pull out the settings from config/email.yml.

Returns a Hash with all symbolized keys.

# File lib/forklift/base/mailer.rb, line 16
def config
  config_file = "#{forklift.config[:project_root]}/config/email.yml"
  @config ||= forklift.utils.load_yml(config_file).deep_symbolize_keys
end
forklift() click to toggle source
# File lib/forklift/base/mailer.rb, line 21
def forklift
  @forklift
end
message_defaults() click to toggle source
# File lib/forklift/base/mailer.rb, line 25
def message_defaults
  {
    from:     "Forklift",
    subject:  "Forklift has moved your database @ #{Time.new}",
    body:     "Forklift has moved your database @ #{Time.new}",
  }
end
send(args, attachment_lines=[]) click to toggle source
# File lib/forklift/base/mailer.rb, line 41
def send(args, attachment_lines=[])
  params = message_defaults
  [:to, :from, :subject, :body].each do |i|
    params[i] = args[i] unless args[i].nil?
  end
  if attachment_lines.length > 0
    params[:attachments] = {"log.txt" => attachment_lines.join("\r\n")}
  end
  deliver(params)
end
send_template(args, template_file, variables, attachment_lines=[]) click to toggle source
# File lib/forklift/base/mailer.rb, line 33
def send_template(args, template_file, variables, attachment_lines=[])
  renderer = ERB.new(File.read(template_file))
  binder = ERBBinding.new(variables)
  body = renderer.result(binder.get_binding)
  args[:body] = body
  send(args, attachment_lines)
end

Private Instance Methods

deliver(params) click to toggle source

Private: Actually deliver the message using Pony.

Returns the raw email from Pony.

# File lib/forklift/base/mailer.rb, line 57
def deliver(params)
  forklift.logger.log("Sending email via #{config[:via]}")
  if params[:html_body].nil?
    params[:html_body] = params[:body]
    params.delete(:body)
  end
  params[:via] = config[:via].to_sym
  params[:via_options] = config[:via_options]
  Pony.mail(params)
end