aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/collection_association.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/collection_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/collection_association.rb24
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