aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/message_delivery.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@basecamp.com>2014-08-17 16:44:30 -0700
committerDavid Heinemeier Hansson <david@basecamp.com>2014-08-17 16:44:30 -0700
commit49c9f850fa3e2484e3aaf20b2479f61b1cc9375e (patch)
tree2f2750a0801c0f2450f6908639973c38d9625963 /actionmailer/lib/action_mailer/message_delivery.rb
parentb2708a635285f2b09040ee9070a8f5a09ab22282 (diff)
parent080296be61105f4f941441a506a6a9fe5c562772 (diff)
downloadrails-49c9f850fa3e2484e3aaf20b2479f61b1cc9375e.tar.gz
rails-49c9f850fa3e2484e3aaf20b2479f61b1cc9375e.tar.bz2
rails-49c9f850fa3e2484e3aaf20b2479f61b1cc9375e.zip
Merge pull request #16485 from seuros/activejob
Integrate ActiveJob / DeliverLater / GlobalID with Rails
Diffstat (limited to 'actionmailer/lib/action_mailer/message_delivery.rb')
-rw-r--r--actionmailer/lib/action_mailer/message_delivery.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/message_delivery.rb b/actionmailer/lib/action_mailer/message_delivery.rb
new file mode 100644
index 0000000000..80a0517bff
--- /dev/null
+++ b/actionmailer/lib/action_mailer/message_delivery.rb
@@ -0,0 +1,45 @@
+require 'delegate'
+
+module ActionMailer
+ class MessageDelivery < Delegator
+ def initialize(mailer, mail_method, *args)
+ @mailer = mailer
+ @mail_method = mail_method
+ @args = args
+ end
+
+ def __getobj__
+ @obj ||= @mailer.send(:new, @mail_method, *@args).message
+ end
+
+ def __setobj__(obj)
+ @obj = obj
+ end
+
+ def message #:nodoc:
+ __getobj__
+ end
+
+ def deliver_later!(options={})
+ enqueue_delivery :deliver!, options
+ end
+
+ def deliver_later(options={})
+ enqueue_delivery :deliver, options
+ 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]
+ end
+ ActionMailer::DeliveryJob.send enqueue_method, *args
+ end
+ end
+end