lib/devise/async/model.rb in devise-async-0.10.2 vs lib/devise/async/model.rb in devise-async-1.0.0beta

- old
+ new

@@ -25,55 +25,33 @@ # processing instead of sending it inline as devise does by # default. def send_devise_notification(notification, *args) return super unless Devise::Async.enabled - # The current locale has to be remembered until the actual sending - # of an email because it is scoped to the current thread. Hence, - # using asynchronous mechanisms that use another thread to send an - # email the currently used locale will be gone later. - args = args_with_current_locale(args) - - # If the record is dirty we keep pending notifications to be enqueued - # by the callback and avoid before commit job processing. - if changed? - devise_pending_notifications << [ notification, args ] - # If the record isn't dirty (aka has already been saved) enqueue right away - # because the callback has already been triggered. + if new_record? || changed? + devise_pending_notifications << [notification, args] else - Devise::Async::Worker.enqueue(notification, self.class.name, self.id.to_s, *args) + deliver_mail_later(notification, self, args) end end # Send all pending notifications. def send_devise_pending_notifications devise_pending_notifications.each do |notification, args| - # Use `id.to_s` to avoid problems with mongoid 2.4.X ids being serialized - # wrong with YAJL. - Devise::Async::Worker.enqueue(notification, self.class.name, self.id.to_s, *args) + deliver_mail_later(notification, self, args) end - @devise_pending_notifications = [] + + @devise_pending_notifications.clear end def devise_pending_notifications @devise_pending_notifications ||= [] end private - def args_with_current_locale(args) - # The default_locale is taken in any case. Hence, the args do not have - # to be adapted if default_locale and current locale are equal. - args = add_current_locale_to_args(args) if I18n.locale != I18n.default_locale - args + def deliver_mail_later(notification, model, args) + devise_mailer.send(notification, model, *args).deliver_later end - - def add_current_locale_to_args(args) - # Devise expects a hash as the last parameter for Mailer methods. - opts = args.last.is_a?(Hash) ? args.pop : {} - opts['locale'] = I18n.locale - args.push(opts) - end - end end end