Skip to content

Instantly share code, notes, and snippets.

@goz
Created February 11, 2011 04:30
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 goz/4f5f5b884694a9d5038e to your computer and use it in GitHub Desktop.
Save goz/4f5f5b884694a9d5038e to your computer and use it in GitHub Desktop.
custom_activerecord_callbacks.rb
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