Skip to content

Commit

Permalink
Let mail() and create!() return what their overridden versions do.
Browse files Browse the repository at this point in the history
This allows us to continue to do MailerClass.mailer_method.deliver
  • Loading branch information
einarmagnus committed Mar 15, 2012
1 parent 4e93240 commit 4ff3e21
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sendgrid.rb
Expand Up @@ -141,14 +141,15 @@ def sendgrid_unique_args(args)
# 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)
super
m = 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)
m
end

else
Expand Down

2 comments on commit 4ff3e21

@dennischeunggroupon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better to use super.tap or returning() for preserve the return value

@einarmagnus
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps. Semantically there is no difference, but it may be safer if someone edits this further.

Please sign in to comment.