diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-11 19:28:32 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-11 19:28:32 -0200 |
commit | 7a036ebd30a6333f22684bdd33dcf5ad4d101d26 (patch) | |
tree | a49115491e36ea6a9b3862d3bd0c70d996534e35 /activerecord/lib/active_record/associations/builder/collection_association.rb | |
parent | 5853c64a4ba77134b7a4ff942b7ae711cb7bcc46 (diff) | |
download | rails-7a036ebd30a6333f22684bdd33dcf5ad4d101d26.tar.gz rails-7a036ebd30a6333f22684bdd33dcf5ad4d101d26.tar.bz2 rails-7a036ebd30a6333f22684bdd33dcf5ad4d101d26.zip |
Revert the whole refactoring in the association builder classes.
This is to get activerecord-deprecated_finders work again
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/collection_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/collection_association.rb | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index b696914883..bc15a49996 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -7,11 +7,22 @@ module ActiveRecord::Associations::Builder CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove] - def self.build_valid_options(options) + def valid_options super + [:table_name, :before_add, :after_add, :before_remove, :after_remove, :extend] end + attr_reader :block_extension + + def initialize(model, name, scope, options) + super + @mod = nil + if block_given? + @mod = Module.new(&Proc.new) + @scope = wrap_scope @scope, @mod + end + end + def self.define_callbacks(model, reflection) super name = reflection.name @@ -21,11 +32,10 @@ module ActiveRecord::Associations::Builder } end - def self.define_extensions(model, name) - if block_given? + def define_extensions(model) + if @mod extension_module_name = "#{model.name.demodulize}#{name.to_s.camelize}AssociationExtension" - extension = Module.new(&Proc.new) - model.parent.const_set(extension_module_name, extension) + model.parent.const_set(extension_module_name, @mod) end end @@ -68,7 +78,9 @@ module ActiveRecord::Associations::Builder CODE end - def self.wrap_scope(scope, mod) + private + + def wrap_scope(scope, mod) if scope proc { |owner| instance_exec(owner, &scope).extending(mod) } else |