aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-04-03 01:35:10 +0100
committerPratik Naik <pratiknaik@gmail.com>2010-04-03 01:35:43 +0100
commit41a2ba652a6b4b4eb3d12b9a2d55cb5b1eb5581a (patch)
treef0513e0de8df95080448e88f85ffb05bc6c7401c
parent684e4d39d60d87273ea74f9a076b3ea308fc2ffe (diff)
downloadrails-41a2ba652a6b4b4eb3d12b9a2d55cb5b1eb5581a.tar.gz
rails-41a2ba652a6b4b4eb3d12b9a2d55cb5b1eb5581a.tar.bz2
rails-41a2ba652a6b4b4eb3d12b9a2d55cb5b1eb5581a.zip
Improve named scope lambda
-rw-r--r--activerecord/lib/active_record/named_scope.rb17
1 files changed, 4 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 86a18f8b6b..50c57783b2 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -99,7 +99,7 @@ module ActiveRecord
#
# expected_options = { :conditions => { :colored => 'red' } }
# assert_equal expected_options, Shirt.colored('red').proxy_options
- def scope(name, options = {}, &block)
+ def scope(name, scope_options = {}, &block)
name = name.to_sym
if !scopes[name] && respond_to?(name, true)
@@ -108,19 +108,10 @@ module ActiveRecord
end
scopes[name] = lambda do |*args|
- scope_options = case options
- when Hash, Relation
- options
- when Proc
- options.call(*args)
- end
-
- relation = if scope_options.is_a?(Hash)
- scoped.apply_finder_options(scope_options)
- else
- scope_options ? scoped.merge(scope_options) : scoped
- end
+ options = scope_options.is_a?(Proc) ? scope_options.call(*args) : scope_options
+ relation = scoped
+ relation = options.is_a?(Hash) ? relation.apply_finder_options(options) : scoped.merge(options) if options
block_given? ? relation.extending(Module.new(&block)) : relation
end