Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module AttributeFu
- module Associations #:nodoc:
- def self.included(base) #:nodoc:
- base.class_eval do
- extend ClassMethods
- class << self; alias_method_chain :has_many, :association_option; end
- class_inheritable_accessor :managed_association_attributes
- write_inheritable_attribute :managed_association_attributes, []
- after_update :save_managed_associations
- end
- end
- ...
- end
- end
- class << self; alias_method_chain :has_many, :association_option; end
- /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `has_many' for class `ActiveRecord::Base' (NameError)
- from /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain'
- from /home/twong/git/physpace/vendor/plugins/attribute_fu/lib/attribute_fu/associations.rb:9:in `included'
- # init.rb
- ActiveRecord::Base.class_eval { include AttributeFu::Associations }
- module AttributeFu
- module Associations
- def self.included(base)
- # base == ActiveRecord::Base (the class)
- base.class_eval do
- # class_eval makes self == ActiveRecord::Base, and makes def define instance methods.
- extend ClassMethods
- # If has_many were an instance method, we could do this
- # alias_method_chain :has_many, :association_option; end
- # but it's a class method, so we have to do the alias_method_chain on
- # the meta-class for ActiveRecord::Base, which is what class << self does.
- class << self; alias_method_chain :has_many, :association_option; end
- end
- end
- end
- end
- class A ; end
- A.class_eval { puts self.inspect ; class << self ; puts self.inspect ; end }
- class << self
- ...
- end
- SomeThing.bar_method
- assoc = SomeThing.new
- assoc.foo_method
- class SomeThing
- def foo_method
- ...
- end
- class << self
- def bar_method
- ...
- end
- end
- end
- def self.has_many_with_association_options
- ...
- end
- class << self
- def has_many_with_association_options
- ...
- end
- end
Add Comment
Please, Sign In to add comment