Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

no longer dependent on Rails.version method. Using ActionMailer::Base…

… instead
  • Loading branch information...
commit f5f780605259d0a55dff8584533b0f65d857e379 1 parent de40bd0
Brad Cantin authored
Showing with 13 additions and 12 deletions.
  1. +13 −12 lib/sendgrid.rb
View
25 lib/sendgrid.rb
@@ -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 defined?(Rails) && 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
Please sign in to comment.
Something went wrong with that request. Please try again.