lib/ahoy_email.rb in ahoy_email-0.0.2 vs lib/ahoy_email.rb in ahoy_email-0.1.0
- old
+ new
@@ -3,51 +3,36 @@
require "nokogiri"
require "addressable/uri"
require "openssl"
require "ahoy_email/processor"
require "ahoy_email/interceptor"
+require "ahoy_email/mailer"
require "ahoy_email/engine"
-ActionMailer::Base.register_interceptor AhoyEmail::Interceptor
-
module AhoyEmail
mattr_accessor :secret_token, :options
self.options = {
- create_message: true,
- track_open: true,
- track_click: true,
- utm_source: nil,
+ message: true,
+ open: true,
+ click: true,
+ utm_params: true,
+ utm_source: proc {|message, mailer| mailer.mailer_name },
utm_medium: "email",
utm_term: nil,
utm_content: nil,
- utm_campaign: nil
+ utm_campaign: proc {|message, mailer| mailer.action_name },
+ user: proc{|message, mailer| User.where(email: message.to.first).first rescue nil }
}
-end
-module ActionMailer
- class Base
- class_attribute :ahoy_options
- self.ahoy_options = {}
+ def self.message_model=(message_model)
+ @message_model = message_model
+ end
- class << self
- def ahoy(options)
- self.ahoy_options = ahoy_options.merge(options)
- end
- end
-
- def ahoy(options)
- @ahoy_options = (@ahoy_options || {}).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 || {})
- AhoyEmail::Processor.new(message, options).process!
-
- message
- end
- alias_method_chain :mail, :ahoy
-
+ def self.message_model
+ @message_model || Ahoy::Message
end
+
end
+
+ActionMailer::Base.send :include, AhoyEmail::Mailer
+ActionMailer::Base.register_interceptor AhoyEmail::Interceptor