Sha256: df07fc6fe1bdcbd29c71e3092d1177d19f2cd2938f64216b0a93bdc9e52f39c1

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

module Gossiper
  class Mailer < ActionMailer::Base

    def mail_for(notification)
      config = config_for(notification)

      config.attachments.each do |filename, file|
        attachments[filename] = file
      end

      config.instance_variables.each do |name, value|
        instance_variable_set("@#{name}", value)
      end

      mail(
        to:      config.to,
        cc:      config.cc,
        bcc:     config.bcc,
        subject: config.subject,
        template_name: config.template_name,
        template_path: config.template_path
      )
    end

    def config_for(notification)
      begin
        klass = "Notifications::#{notification.kind.classify}Notification"
        klass.constantize.new(notification)
      rescue NameError
        Gossiper::EmailConfig.new(notification)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gossiper-0.1.0 lib/gossiper/mailer.rb