Created
November 2, 2015 14:19
-
-
Save timoschilling/1c2a6e0cdfe72de01413 to your computer and use it in GitHub Desktop.
Skipable Trailblazer Callbacks
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 SkipableCallbacks | |
def initialize(params, options = {}) | |
@skip_callbacks = params.delete(:skip_callbacks) || {} | |
super | |
end | |
def dispatch!(name = :default) | |
org_callbacks = self.class.callbacks[name] | |
self.class.callbacks[name] = org_callbacks.clone | |
@skip_callbacks[name] && @skip_callbacks[name].each do |callback| | |
self.class.callbacks[name].remove! *callback | |
end | |
res = super | |
self.class.callbacks[name] = org_callbacks | |
res | |
end | |
end | |
Op.call params.merge!(skip_callbacks: { after_save: [[:on_change, :recalculate_post_vote]]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment