aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb19
-rw-r--r--activerecord/lib/active_record/associations/builder/collection_association.rb8
2 files changed, 17 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index df9cc65758..4efd5aa8ba 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -42,14 +42,29 @@ module ActiveRecord::Associations::Builder
def initialize(name, scope, options, extension)
@name = name
- @scope = scope
@options = options
self.class.validate_options(options)
+ @scope = self.class.build_scope(scope, extension)
+ end
+
+ def self.build_scope(scope, extension)
+ new_scope = scope
+
if scope && scope.arity == 0
- @scope = proc { instance_exec(&scope) }
+ new_scope = proc { instance_exec(&scope) }
+ end
+
+ if extension
+ new_scope = wrap_scope new_scope, extension
end
+
+ new_scope
+ end
+
+ def self.wrap_scope(scope, extension)
+ scope
end
def build(model)
diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb
index 2676037e80..521597e822 100644
--- a/activerecord/lib/active_record/associations/builder/collection_association.rb
+++ b/activerecord/lib/active_record/associations/builder/collection_association.rb
@@ -12,14 +12,6 @@ module ActiveRecord::Associations::Builder
:after_add, :before_remove, :after_remove, :extend]
end
- def initialize(name, scope, options, extension)
- super
-
- if extension
- @scope = self.class.wrap_scope @scope, extension
- end
- end
-
def self.define_callbacks(model, reflection)
super
name = reflection.name