Sha256: b3c4b814511268f0d17238179356cb8963eb5fb125d84b0d64d8e5d4a57dc8b0

Contents?: true

Size: 964 Bytes

Versions: 3

Compression:

Stored size: 964 Bytes

Contents

module AhoyEmail
  module Mailer
    extend ActiveSupport::Concern

    included do
      attr_writer :ahoy_options
      after_action :save_ahoy_options
    end

    class_methods do
      def track(**options)
        before_action(options.slice(:only, :except)) do
          self.ahoy_options = ahoy_options.merge(message: true).merge(options.except(:only, :except))
        end
      end
    end

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

    def ahoy_options
      @ahoy_options ||= AhoyEmail.default_options
    end

    def save_ahoy_options
      if ahoy_options[:message]
        Safely.safely do
          options = {}
          ahoy_options.each do |k, v|
            # execute options in mailer content
            options[k] = v.respond_to?(:call) ? instance_exec(&v) : v
          end

          AhoyEmail::Processor.new(self, options).perform
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ahoy_email-1.0.2 lib/ahoy_email/mailer.rb
ahoy_email-1.0.1 lib/ahoy_email/mailer.rb
ahoy_email-1.0.0 lib/ahoy_email/mailer.rb