module Devise::Models::Async

Protected Instance Methods

devise_pending_notifications() click to toggle source
# File lib/devise/async/model.rb, line 46
def devise_pending_notifications
  @devise_pending_notifications ||= []
end
send_devise_notification(notification, *args) click to toggle source

This method overwrites devise's own `send_devise_notification` to capture all email notifications and enqueue it for background processing instead of sending it inline as devise does by default.

Calls superclass method
# File lib/devise/async/model.rb, line 27
def send_devise_notification(notification, *args)
  return super unless Devise::Async.enabled

  if new_record? || changed?
    devise_pending_notifications << [notification, args]
  else
    deliver_mail_later(notification, self, args)
  end
end
send_devise_pending_notifications() click to toggle source

Send all pending notifications.

# File lib/devise/async/model.rb, line 38
def send_devise_pending_notifications
  devise_pending_notifications.each do |notification, args|
    deliver_mail_later(notification, self, args)
  end

  @devise_pending_notifications.clear
end

Private Instance Methods

deliver_mail_later(notification, model, args) click to toggle source
# File lib/devise/async/model.rb, line 52
def deliver_mail_later(notification, model, args)
  devise_mailer.send(notification, model, *args).deliver_later
end