Created
July 15, 2022 17:51
-
-
Save rreinhardt9/1f7259d5a4d8d359457ecfa1e9a20fc8 to your computer and use it in GitHub Desktop.
Re-creating the "Suppressible" concern that was shown in this screencast from DHH: https://www.youtube.com/watch?v=m1jOWu7woKM
This file contains hidden or 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 Suppressible | |
extend ActiveSupport::Concern | |
class_methods do | |
def suppress | |
self.suppressed = true | |
yield | |
ensure | |
self.suppressed = false | |
end | |
def suppressed? | |
suppressed == true | |
end | |
private | |
attr_accessor :suppressed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, maybe the answer there is unless hooks on the specific callbacks