mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix ActionMailer::Async docs and update to follow coding conventions
This commit is contained in:
parent
b64488dcd3
commit
e2abd8da2d
2 changed files with 40 additions and 38 deletions
|
@ -1,39 +1,41 @@
|
|||
require 'delegate'
|
||||
|
||||
module ActionMailer::Async
|
||||
def method_missing(method_name, *args)
|
||||
if action_methods.include?(method_name.to_s)
|
||||
QueuedMessage.new(queue, self, method_name, *args)
|
||||
else
|
||||
super
|
||||
module ActionMailer
|
||||
module Async
|
||||
def method_missing(method_name, *args)
|
||||
if action_methods.include?(method_name.to_s)
|
||||
QueuedMessage.new(queue, self, method_name, *args)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def queue
|
||||
Rails.queue
|
||||
end
|
||||
|
||||
class QueuedMessage < ::Delegator
|
||||
attr_reader :queue
|
||||
|
||||
def initialize(queue, mailer_class, method_name, *args)
|
||||
@queue = queue
|
||||
@mailer_class = mailer_class
|
||||
@method_name = method_name
|
||||
@args = args
|
||||
end
|
||||
|
||||
def __getobj__
|
||||
@actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
|
||||
end
|
||||
|
||||
def run
|
||||
__getobj__.deliver
|
||||
end
|
||||
|
||||
# Will push the message onto the Queue to be processed
|
||||
def deliver
|
||||
@queue << self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def queue
|
||||
Rails.queue
|
||||
end
|
||||
|
||||
class QueuedMessage < ::Delegator
|
||||
attr_reader :queue
|
||||
|
||||
def initialize(queue, mailer_class, method_name, *args)
|
||||
@queue = queue
|
||||
@mailer_class = mailer_class
|
||||
@method_name = method_name
|
||||
@args = args
|
||||
end
|
||||
|
||||
def __getobj__
|
||||
@actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
|
||||
end
|
||||
|
||||
def run
|
||||
__getobj__.deliver
|
||||
end
|
||||
|
||||
# Will push the message onto the Queue to be processed
|
||||
def deliver
|
||||
@queue << self
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -457,10 +457,11 @@ module ActionMailer #:nodoc:
|
|||
end
|
||||
|
||||
# Will force ActionMailer to push new messages to the queue defined
|
||||
# in the ActionMailer class when set to true
|
||||
# in the ActionMailer class when set to true.
|
||||
#
|
||||
# class WelcomeMailer < ActionMailer::Base
|
||||
# self.async = true
|
||||
# end
|
||||
def async=(truth)
|
||||
if truth
|
||||
require 'action_mailer/async'
|
||||
|
@ -785,5 +786,4 @@ module ActionMailer #:nodoc:
|
|||
|
||||
ActiveSupport.run_load_hooks(:action_mailer, self)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue