module Devise::Orm::DirtyTrackingMongoidMethods

def devise_email_before_last_save

def devise_email_before_last_save
  respond_to?(:email_previously_was) ? email_previously_was : email_was
end

def devise_email_in_database

def devise_email_in_database
  email_was
end

def devise_respond_to_and_will_save_change_to_attribute?(attribute)

def devise_respond_to_and_will_save_change_to_attribute?(attribute)
  respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?")
end

def devise_saved_change_to_email?

def devise_saved_change_to_email?
  respond_to?(:email_previously_changed?) ? email_previously_changed? : email_changed?
end

def devise_saved_change_to_encrypted_password?

def devise_saved_change_to_encrypted_password?
  respond_to?(:encrypted_password_previously_changed?) ? encrypted_password_previously_changed? : encrypted_password_changed?
end

def devise_unconfirmed_email_will_change!

def devise_unconfirmed_email_will_change!
  # Mongoid's will_change! doesn't force unchanged attributes into updates,
  # so we override changed_attributes to make it see a difference.
  unconfirmed_email_will_change!
  changed_attributes["unconfirmed_email"] = nil
end

def devise_will_save_change_to_email?

def devise_will_save_change_to_email?
  email_changed?
end