Skip to content

Instantly share code, notes, and snippets.

@timoschilling
Created November 2, 2015 14:19
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 timoschilling/1c2a6e0cdfe72de01413 to your computer and use it in GitHub Desktop.
Save timoschilling/1c2a6e0cdfe72de01413 to your computer and use it in GitHub Desktop.
Skipable Trailblazer Callbacks
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