Created
December 23, 2017 00:44
-
-
Save finbarr/371ac0f3a1504122f75cef07dfb43fc1 to your computer and use it in GitHub Desktop.
SmarterChanged
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
module SmarterChanged | |
extend ActiveSupport::Concern | |
def changed? | |
cache = Thread.current[:smarter_changed] | |
wipe = false | |
if cache.nil? | |
cache = Thread.current[:smarter_changed] = {} | |
wipe = true | |
end | |
begin | |
key = _id.to_s | |
return cache[key] if cache.has_key?(key) | |
cache[key] = super | |
ensure | |
Thread.current[:smarter_changed] = nil if wipe | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment