Created
August 3, 2010 13:26
-
-
Save jagira/506368 to your computer and use it in GitHub Desktop.
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
def add_association_callbacks(association_name, options) | |
callbacks = %w(before_add after_add before_remove after_remove) | |
callbacks.each do |callback_name| | |
full_callback_name = "#{callback_name}_for_#{association_name}" | |
defined_callbacks = options[callback_name.to_sym] | |
if options.has_key?(callback_name.to_sym) | |
class_inheritable_reader full_callback_name.to_sym | |
write_inheritable_attribute(full_callback_name.to_sym, [defined_callbacks].flatten) | |
else | |
write_inheritable_attribute(full_callback_name.to_sym, []) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment