-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dirty tracking conditionals for different versions (#5575)
We have an number of conditions due to how dirty tracking changed around Rails 5.1, that implement methods using one or another method call. I might need more of this for mongo upgrades based on an initial investigation, plus this makes the code really hard to reason about sometimes with these many conditionals. While I want to drop support for older versions of Rails soon, this centralization of dirty methods that are used by devise conditionally simplifies the usage considerably across the board, moves the version condition to a single place, and will make it easier to refactor later once we drop older Rails version by simply removing the `devise_*` versions of the methods, alongside the prefix on the method calls for the most part, since those methods follow the naming of the newer Rails versions.
- Loading branch information
1 parent
232c855
commit 367ea42
Showing
9 changed files
with
90 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Devise | ||
module OrmDirtyTracking # :nodoc: | ||
def self.activerecord51? | ||
defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x") | ||
end | ||
|
||
if activerecord51? | ||
def devise_email_before_last_save | ||
email_before_last_save | ||
end | ||
|
||
def devise_email_in_database | ||
email_in_database | ||
end | ||
|
||
def devise_saved_change_to_email? | ||
saved_change_to_email? | ||
end | ||
|
||
def devise_saved_change_to_encrypted_password? | ||
saved_change_to_encrypted_password? | ||
end | ||
|
||
def devise_will_save_change_to_email? | ||
will_save_change_to_email? | ||
end | ||
|
||
def devise_respond_to_and_will_save_change_to_attribute?(attribute) | ||
respond_to?("will_save_change_to_#{attribute}?") && send("will_save_change_to_#{attribute}?") | ||
end | ||
else | ||
def devise_email_before_last_save | ||
email_was | ||
end | ||
|
||
def devise_email_in_database | ||
email_was | ||
end | ||
|
||
def devise_saved_change_to_email? | ||
email_changed? | ||
end | ||
|
||
def devise_saved_change_to_encrypted_password? | ||
encrypted_password_changed? | ||
end | ||
|
||
def devise_will_save_change_to_email? | ||
email_changed? | ||
end | ||
|
||
def devise_respond_to_and_will_save_change_to_attribute?(attribute) | ||
respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters