lib/ahoy_email.rb in ahoy_email-1.0.2 vs lib/ahoy_email.rb in ahoy_email-1.0.3
- old
+ new
@@ -27,11 +27,11 @@
utm_source: -> { mailer_name },
utm_medium: "email",
utm_term: nil,
utm_content: nil,
utm_campaign: -> { action_name },
- user: -> { @user || (respond_to?(:params) && params && params[:user]) || (message.to.size == 1 ? (User.find_by(email: message.to.first) rescue nil) : nil) },
+ user: -> { @user || (respond_to?(:params) && params && params[:user]) || (message.to.try(:size) == 1 ? (User.find_by(email: message.to.first) rescue nil) : nil) },
mailer: -> { "#{self.class.name}##{action_name}" },
url_options: {},
extra: {},
unsubscribe_links: false
}
@@ -39,11 +39,11 @@
self.track_method = lambda do |data|
message = data[:message]
ahoy_message = AhoyEmail.message_model.new
ahoy_message.to = Array(message.to).join(", ") if ahoy_message.respond_to?(:to=)
- ahoy_message.user = data[:user]
+ ahoy_message.user = data[:user] if ahoy_message.respond_to?(:user=)
ahoy_message.mailer = data[:mailer] if ahoy_message.respond_to?(:mailer=)
ahoy_message.subject = message.subject if ahoy_message.respond_to?(:subject=)
ahoy_message.content = message.encoded if ahoy_message.respond_to?(:content=)
@@ -63,11 +63,13 @@
self.subscribers = []
self.preserve_callbacks = []
+ self.message_model = -> { ::Ahoy::Message }
+
def self.message_model
- model = (defined?(@message_model) && @message_model) || ::Ahoy::Message
+ model = defined?(@@message_model) && @@message_model
model = model.call if model.respond_to?(:call)
model
end
end