Skip to content

Instantly share code, notes, and snippets.

@finbarr
Created December 23, 2017 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finbarr/371ac0f3a1504122f75cef07dfb43fc1 to your computer and use it in GitHub Desktop.
Save finbarr/371ac0f3a1504122f75cef07dfb43fc1 to your computer and use it in GitHub Desktop.
SmarterChanged
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