Created
February 6, 2012 03:56
-
-
Save jwigal/1749452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Delayed Job will let you do this: | |
MyMailer.delay.mailer_action(args) | |
but you can't do this because of yaml serialization: | |
MyMailer.mailer_action(args).delay.deliver | |
Most cases this works fine, but I need this as a before_destroy callback. my data is gone when | |
the mailer fires. | |
Usage: | |
mail_object = MyMailer.mailer_action(args) | |
DelayedMailer.new(mail_object).deliver | |
=end | |
class DelayedMailer | |
attr_reader :mail_object, :settings | |
def initialize(mail_object) | |
@mail_source = mail_object.to_s | |
@settings = mail_object.delivery_method.settings | |
self | |
end | |
def mailer | |
m = Mail::Message.new(@mail_source) | |
m.delivery_method ::ActionMailer::Base.delivery_method, @settings | |
m | |
end | |
def deliver | |
mailer.deliver | |
end | |
handle_asynchronously :deliver | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment