Skip to content

Instantly share code, notes, and snippets.

@D1plo1d
Last active August 29, 2015 14:01
Show Gist options
  • Save D1plo1d/ec857c759cb2b1828bd2 to your computer and use it in GitHub Desktop.
Save D1plo1d/ec857c759cb2b1828bd2 to your computer and use it in GitHub Desktop.
module HardDestroyCallbacks
extend ActiveSupport::Concern
included do
define_callbacks :hard_destroy
around_destroy :run_hard_destroy_callbacks
def run_hard_destroy_callbacks
return yield unless deleted_at.present?
run_callbacks :hard_destroy do
yield
end
end
end
module ClassMethods
def before_hard_destroy(&block)
set_callback :hard_destroy, :before, &block
end
def after_hard_destroy(&block)
set_callback :hard_destroy, :after, &block
end
def around_hard_destroy(&block)
set_callback :hard_destroy, :around, &block
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment