Sha256: 230b0c91c576ad9a29f91a232336edd2a99273a2a8b0f65c40c69c3350f9fed6

Contents?: true

Size: 911 Bytes

Versions: 1

Compression:

Stored size: 911 Bytes

Contents

module AhoyEmail
  module Mailer

    def self.included(base)
      base.extend ClassMethods
      base.class_eval do
        class_attribute :ahoy_options
        self.ahoy_options = {}
        alias_method_chain :mail, :ahoy
      end
    end

    module ClassMethods
      def track(options)
        self.ahoy_options = ahoy_options.merge(message: true).merge(options)
      end
    end

    def track(options)
      @ahoy_options = (@ahoy_options || {}).merge(message: true).merge(options)
    end

    def mail_with_ahoy(headers = {}, &block)
      message = mail_without_ahoy(headers, &block)

      options = AhoyEmail.options.merge(self.class.ahoy_options).merge(@ahoy_options || {})
      options.each do |k, v|
        if v.respond_to?(:call)
          options[k] = v.call(message, self)
        end
      end
      AhoyEmail::Processor.new(message, options).process

      message
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ahoy_email-0.2.0 lib/ahoy_email/mailer.rb