lib/devise/async/model.rb in devise-async-0.3.0 vs lib/devise/async/model.rb in devise-async-0.3.1
- old
+ new
@@ -2,16 +2,24 @@
module Async
module Model
extend ActiveSupport::Concern
included do
- after_commit :send_devise_pending_notifications
+ if respond_to?(:after_commit) # AR only
+ after_commit :send_devise_pending_notifications
+ else # mongoid
+ after_save :send_devise_pending_notifications
+ end
end
protected
def send_devise_notification(notification)
- devise_pending_notifications << notification
+ if changed?
+ devise_pending_notifications << notification
+ else
+ Devise::Async::Worker.enqueue(notification, self.class.name, self.id.to_s)
+ end
end
def send_devise_pending_notifications
devise_pending_notifications.each do |notification|
# Use `id.to_s` to avoid problems with mongoid 2.4.X ids being serialized