Created
March 23, 2009 18:11
-
-
Save eschulte/83699 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
module ActiveRecord::Associations::ClassMethods | |
%w{has_and_belongs_to_many has_many has_one}.each do |meth| | |
eval(<<METHOD_OVERRIDE | |
# intercepting the #{meth} method to add the :as_component option | |
def #{meth}_with_component(name, options = {}) | |
if options.delete(:as_component) | |
options[:after_add] = :tell_my_parents | |
self.components ||= [] | |
self.components << name | |
end | |
#{meth}_without_component(name, options) | |
end | |
alias_method_chain(:#{meth}, :component) | |
METHOD_OVERRIDE | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment