diff options
author | Brian Cardarella <bcardarella@gmail.com> | 2012-06-23 16:06:04 -0400 |
---|---|---|
committer | Brian Cardarella <bcardarella@gmail.com> | 2012-06-23 16:06:04 -0400 |
commit | 5337149caf28b9d8bfe907584511453044890ebd (patch) | |
tree | d89262bc5dc9f908509ade73c28c96d736179d9f /actionmailer/lib/action_mailer | |
parent | d1d6c364d0287a5aae667332ed9a9b25990fd207 (diff) | |
download | rails-5337149caf28b9d8bfe907584511453044890ebd.tar.gz rails-5337149caf28b9d8bfe907584511453044890ebd.tar.bz2 rails-5337149caf28b9d8bfe907584511453044890ebd.zip |
Use Delegator for a cleaner QueuedMessage class
Credit goes to *Nicolás Sanguinetti* (foca) for this suggestion
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/async.rb | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/actionmailer/lib/action_mailer/async.rb b/actionmailer/lib/action_mailer/async.rb index fd62c57790..620f47f060 100644 --- a/actionmailer/lib/action_mailer/async.rb +++ b/actionmailer/lib/action_mailer/async.rb @@ -1,3 +1,5 @@ +require 'delegate' + module ActionMailer::Async def self.included(base) base.extend(ClassMethods) @@ -13,17 +15,19 @@ module ActionMailer::Async end end - class QueuedMessage - delegate :to_s, :to => :actual_message - + class QueuedMessage < ::Delegator def initialize(mailer_class, method_name, *args) @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 - actual_message.deliver + __getobj__.deliver end # Will push the message onto the Queue to be processed @@ -36,14 +40,5 @@ module ActionMailer::Async Rails.queue << self end end - - # The original ActionMailer message - def actual_message - @actual_message ||= @mailer_class.send(:new, @method_name, *@args).message - end - - def method_missing(method_name, *args) - actual_message.send(method_name, *args) - end end end |