Permalink
Browse files

blocks removed from all the ActiveRelation query_methods, extend meth…

…od added instead

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 026cec3 commit 47134a04bbce216f9c31473b1a0c1a077d624692 @spastorino spastorino committed with josevalim Jun 25, 2010
@@ -328,6 +328,15 @@ def inspect
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)
@@ -11,19 +11,17 @@ module QueryMethods
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
end
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 @@ def select(*args)
[: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 @@ def #{query_method}(*args, &block)
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
@@ -618,7 +618,7 @@ def test_except
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

0 comments on commit 47134a0

Please sign in to comment.