Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated rdoc / guides / release notes related to ActiveJob / ActionMa…
…iler
- Loading branch information
1 parent
f4ee114
commit 9e7f4a9
Showing
11 changed files
with
141 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,112 @@ | ||
require 'delegate' | ||
|
||
module ActionMailer | ||
|
||
# The ActionMailer::MessageDeliver class is used by ActionMailer::Base when | ||
# creating a new mailer. MessageDeliver is a wrapper (Delegator subclass) | ||
# around a lazy created Mail::Message. You can get direct access to the | ||
# Mail::Message, deliver the email or schedule the email to be sent through ActiveJob. | ||
# | ||
# Notifier.welcome(david) # an ActionMailer::MessageDeliver object | ||
# Notifier.welcome(david).deliver_now # sends the email | ||
# Notifier.welcome(david).deliver_later # enqueue the deliver email job to ActiveJob | ||
# Notifier.welcome(david).message # a Mail::Message object | ||
class MessageDelivery < Delegator | ||
def initialize(mailer, mail_method, *args) | ||
def initialize(mailer, mail_method, *args) #:nodoc: | ||
@mailer = mailer | ||
@mail_method = mail_method | ||
@args = args | ||
end | ||
|
||
def __getobj__ | ||
def __getobj__ #:nodoc: | ||
@obj ||= @mailer.send(:new, @mail_method, *@args).message | ||
end | ||
|
||
def __setobj__(obj) | ||
def __setobj__(obj) #:nodoc: | ||
@obj = obj | ||
end | ||
|
||
def message #:nodoc: | ||
# Returns the Mail::Message object | ||
def message | ||
__getobj__ | ||
end | ||
|
||
# Enqueues the message to be delivered through ActiveJob. When the | ||
# ActiveJob job runs it will send the email using #deliver_now!. That | ||
# means that the message will be sent bypassing checking perform_deliveries | ||
# and raise_delivery_errors, so use with caution. | ||
# | ||
# ==== Examples | ||
# | ||
# Notifier.welcome(david).deliver_later | ||
# Notifier.welcome(david).deliver_later(in: 1.hour) | ||
# Notifier.welcome(david).deliver_later(at: 10.hours.from_now) | ||
# | ||
# ==== Options | ||
# * <tt>in</tt> - Enqueue the message to be delivered with a delay | ||
# * <tt>at</tt> - Enqueue the message to be delivered at (after) a specific date / time | ||
def deliver_later!(options={}) | ||
enqueue_delivery :deliver_now!, options | ||
end | ||
|
||
# Enqueues the message to be delivered through ActiveJob. When the | ||
# ActiveJob job runs it will send the email using #deliver_now. | ||
# | ||
# ==== Examples | ||
# | ||
# Notifier.welcome(david).deliver_later | ||
# Notifier.welcome(david).deliver_later(in: 1.hour) | ||
# Notifier.welcome(david).deliver_later(at: 10.hours.from_now) | ||
# | ||
# ==== Options | ||
# * <tt>in</tt> - Enqueue the message to be delivered with a delay | ||
# * <tt>at</tt> - Enqueue the message to be delivered at (after) a specific date / time | ||
def deliver_later(options={}) | ||
enqueue_delivery :deliver_now, options | ||
end | ||
|
||
# Delivers a message. The message will be sent bypassing checking perform_deliveries | ||
# and raise_delivery_errors, so use with caution. | ||
# | ||
# Notifier.welcome(david).deliver_now! | ||
# | ||
def deliver_now! | ||
message.deliver! | ||
end | ||
|
||
# Delivers a message: | ||
# | ||
# Notifier.welcome(david).deliver_now | ||
# | ||
def deliver_now | ||
message.deliver | ||
end | ||
|
||
def deliver! | ||
ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed on Rails 5. " \ | ||
"Use #deliver_now! to deliver immediately or #deliver_later! to deliver through ActiveJob" | ||
def deliver! #:nodoc: | ||
ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed in Rails 5. " \ | ||
"Use #deliver_now! to deliver immediately or #deliver_later! to deliver through ActiveJob." | ||
deliver_now! | ||
end | ||
|
||
def deliver | ||
ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed on Rails 5. " \ | ||
"Use #deliver_now to deliver immediately or #deliver_later to deliver through ActiveJob" | ||
def deliver #:nodoc: | ||
ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed in Rails 5. " \ | ||
"Use #deliver_now to deliver immediately or #deliver_later to deliver through ActiveJob." | ||
deliver_now | ||
end | ||
|
||
private | ||
def enqueue_delivery(delivery_method, options={}) | ||
args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args | ||
enqueue_method = :enqueue | ||
if options[:at] | ||
enqueue_method = :enqueue_at | ||
args.unshift options[:at] | ||
elsif options[:in] | ||
enqueue_method = :enqueue_in | ||
args.unshift options[:in] | ||
|
||
def enqueue_delivery(delivery_method, options={}) | ||
args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args | ||
enqueue_method = :enqueue | ||
if options[:at] | ||
enqueue_method = :enqueue_at | ||
args.unshift options[:at] | ||
elsif options[:in] | ||
enqueue_method = :enqueue_in | ||
args.unshift options[:in] | ||
end | ||
ActionMailer::DeliveryJob.send enqueue_method, *args | ||
end | ||
ActionMailer::DeliveryJob.send enqueue_method, *args | ||
end | ||
end | ||
end |
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
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
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
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
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
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