1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

blocks removed from all the ActiveRelation query_methods, extend method added instead

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Santiago Pastorino 2010-06-25 20:31:10 -03:00 committed by José Valim
parent 026cec3390
commit 47134a04bb
3 changed files with 14 additions and 9 deletions

View file

@ -328,6 +328,15 @@ module ActiveRecord
to_a.inspect
end
def extend(*args, &block)
if block_given?
apply_modules Module.new(&block)
self
else
super
end
end
protected
def method_missing(method, *args, &block)

View file

@ -11,9 +11,8 @@ module ActiveRecord
next if [:where, :having, :select].include?(query_method)
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
def #{query_method}(*args, &block)
def #{query_method}(*args)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = Array.wrap(args.flatten).reject {|x| x.blank? }
new_relation.#{query_method}_values += value if value.present?
new_relation
@ -21,9 +20,8 @@ module ActiveRecord
CEVAL
end
def reorder(*args, &block)
def reorder(*args)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = Array.wrap(args.flatten).reject {|x| x.blank? }
new_relation.order_values = value if value.present?
new_relation
@ -42,9 +40,8 @@ module ActiveRecord
[:where, :having].each do |query_method|
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
def #{query_method}(*args, &block)
def #{query_method}(*args)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = build_where(*args)
new_relation.#{query_method}_values += Array.wrap(value) if value.present?
new_relation
@ -56,9 +53,8 @@ module ActiveRecord
attr_accessor :"#{query_method}_value"
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
def #{query_method}(value = true, &block)
def #{query_method}(value = true)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
new_relation.#{query_method}_value = value
new_relation
end

View file

@ -618,7 +618,7 @@ class RelationTest < ActiveRecord::TestCase
end
def test_anonymous_extension
relation = Post.where(:author_id => 1).order('id ASC') do
relation = Post.where(:author_id => 1).order('id ASC').extend do
def author
'lifo'
end