aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record.rb2
-rw-r--r--activerecord/lib/active_record/named_scope.rb5
-rw-r--r--activerecord/lib/active_record/observer.rb9
-rw-r--r--activerecord/lib/active_record/relation.rb11
4 files changed, 15 insertions, 12 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 8379f6a66f..0777f85869 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -1,5 +1,5 @@
#--
-# Copyright (c) 2004-2010 David Heinemeier Hansson
+# Copyright (c) 2004-2011 David Heinemeier Hansson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 0f421560f0..d291632260 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -102,10 +102,9 @@ module ActiveRecord
def scope(name, scope_options = {})
name = name.to_sym
valid_scope_name?(name)
-
extension = Module.new(&Proc.new) if block_given?
- scopes[name] = lambda do |*args|
+ scope_proc = lambda do |*args|
options = scope_options.respond_to?(:call) ? scope_options.call(*args) : scope_options
relation = if options.is_a?(Hash)
@@ -119,6 +118,8 @@ module ActiveRecord
extension ? relation.extending(extension) : relation
end
+ self.scopes = self.scopes.merge name => scope_proc
+
singleton_class.send(:redefine_method, name, &scopes[name])
end
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb
index 8b011ad9af..0893d7e337 100644
--- a/activerecord/lib/active_record/observer.rb
+++ b/activerecord/lib/active_record/observer.rb
@@ -104,10 +104,17 @@ module ActiveRecord
def define_callbacks(klass)
observer = self
+ observer_name = observer.class.name.underscore.gsub('/', '__')
ActiveRecord::Callbacks::CALLBACKS.each do |callback|
next unless respond_to?(callback)
- klass.send(callback){|record| observer.send(callback, record)}
+ callback_meth = :"_notify_#{observer_name}_for_#{callback}"
+ unless klass.respond_to?(callback_meth)
+ klass.send(:define_method, callback_meth) do
+ observer.send(callback, self)
+ end
+ klass.send(callback, callback_meth)
+ end
end
end
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index c6cd8891e3..3c7533ea48 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -67,15 +67,10 @@ module ActiveRecord
end
def respond_to?(method, include_private = false)
- return true if arel.respond_to?(method, include_private) || Array.method_defined?(method) || @klass.respond_to?(method, include_private)
-
- if match = DynamicFinderMatch.match(method)
- return true if @klass.send(:all_attributes_exists?, match.attribute_names)
- elsif match = DynamicScopeMatch.match(method)
- return true if @klass.send(:all_attributes_exists?, match.attribute_names)
- else
+ arel.respond_to?(method, include_private) ||
+ Array.method_defined?(method) ||
+ @klass.respond_to?(method, include_private) ||
super
- end
end
def to_a