-
-
Save goz/4f5f5b884694a9d5038e to your computer and use it in GitHub Desktop.
custom_activerecord_callbacks.rb
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 ActiveRecord | |
module SweetCustomCallbacks | |
def self.included(base) | |
base.class_eval do | |
alias_method_chain :create_or_update, :sweet_custom_callbacks | |
def self.before_before_save(*callbacks, &block) | |
callbacks << block if block_given? | |
write_inheritable_array(:before_before_save,callbacks) | |
end | |
end | |
end | |
def before_before_save() end | |
def create_or_update_with_sweet_custom_callbacks | |
return false if callback(:before_before_save) == false | |
create_or_update_without_sweet_custom_callbacks | |
end | |
end | |
class Base | |
include SweetCustomCallbacks #include our module in ActiveRecord::Base | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment