Permalink
Browse files

Merge pull request #2 from bcantin/master

Remove dependency on Rails version checking.
  • Loading branch information...
2 parents 4331623 + f5f7806 commit e062e5eedc089298afe43e7c2e081fc6497e2d7a @stephenb committed Sep 8, 2011
Showing with 13 additions and 12 deletions.
  1. +13 −12 lib/sendgrid.rb
View
@@ -133,38 +133,39 @@ def sendgrid_unique_args(args)
@sg_unique_args = args
end
- # only override the appropriet methods for the current rails version
- if Rails.version < '3.0.0'
+ # only override the appropriate methods for the current ActionMailer version
+ if ActionMailer::Base.respond_to?(:mail)
+
+ protected
# Sets the custom X-SMTPAPI header after creating the email but before delivery
- # NOTE: This override is used for Rails 2 ActionMailer classes.
- def create!(method_name, *parameters)
+ # NOTE: This override is used for Rails 3 ActionMailer classes.
+ def mail(headers={}, &block)
super
if @sg_substitutions && !@sg_substitutions.empty?
@sg_substitutions.each do |find, replace|
raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
end
end
- puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
- @mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
+ puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
+ self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
end
else
- protected
-
# Sets the custom X-SMTPAPI header after creating the email but before delivery
- # NOTE: This override is used for Rails 3 ActionMailer classes.
- def mail(headers={}, &block)
+ # NOTE: This override is used for Rails 2 ActionMailer classes.
+ def create!(method_name, *parameters)
super
if @sg_substitutions && !@sg_substitutions.empty?
@sg_substitutions.each do |find, replace|
raise ArgumentError.new("Array for #{find} is not the same size as the recipient array") if replace.size != @sg_recipients.size
end
end
- puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(message)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
- self.headers['X-SMTPAPI'] = sendgrid_json_headers(message)
+ puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
+ @mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
end
+
end
private

0 comments on commit e062e5e

Please sign in to comment.