aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-02-24 17:58:11 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-02-24 18:22:23 -0300
commit5cbee323aa14c761a7651113f4282be4ec2d0e7f (patch)
tree1f0f989e0757158db33014846f0500fe97b2c9fb
parent1509844cdd53e137f8ae02d2df52d811357426ec (diff)
downloadrails-5cbee323aa14c761a7651113f4282be4ec2d0e7f.tar.gz
rails-5cbee323aa14c761a7651113f4282be4ec2d0e7f.tar.bz2
rails-5cbee323aa14c761a7651113f4282be4ec2d0e7f.zip
Make explicit the method will raise an exception
Taking the wise advice of @carlosantoniodasilva
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb20
1 files changed, 10 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 20e23cb003..225677085f 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -112,7 +112,7 @@ module ActiveRecord
#
# User.includes(:posts).where('posts.name = ?', 'example').references(:posts)
def includes(*args)
- has_arguments?("includes", args)
+ check_if_method_has_arguments!("includes", args)
spawn.includes!(*args)
end
@@ -130,7 +130,7 @@ module ActiveRecord
# FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" =
# "users"."id"
def eager_load(*args)
- has_arguments?("eager_load", args)
+ check_if_method_has_arguments!("eager_load", args)
spawn.eager_load!(*args)
end
@@ -144,7 +144,7 @@ module ActiveRecord
# User.preload(:posts)
# => SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN (1, 2, 3)
def preload(*args)
- has_arguments?("preload", args)
+ check_if_method_has_arguments!("preload", args)
spawn.preload!(*args)
end
@@ -162,7 +162,7 @@ module ActiveRecord
# User.includes(:posts).where("posts.name = 'foo'").references(:posts)
# # => Query now knows the string references posts, so adds a JOIN
def references(*args)
- has_arguments?("references", args)
+ check_if_method_has_arguments!("references", args)
spawn.references!(*args)
end
@@ -242,7 +242,7 @@ module ActiveRecord
# User.group('name AS grouped_name, age')
# => [#<User id: 3, name: "Foo", age: 21, ...>, #<User id: 2, name: "Oscar", age: 21, ...>, #<User id: 5, name: "Foo", age: 23, ...>]
def group(*args)
- has_arguments?("group", args)
+ check_if_method_has_arguments!("group", args)
spawn.group!(*args)
end
@@ -273,7 +273,7 @@ module ActiveRecord
# User.order(:name, email: :desc)
# => SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
def order(*args)
- has_arguments?("order", args)
+ check_if_method_has_arguments!("order", args)
spawn.order!(*args)
end
@@ -299,7 +299,7 @@ module ActiveRecord
#
# generates a query with 'ORDER BY name ASC, id ASC'.
def reorder(*args)
- has_arguments?("reorder", args)
+ check_if_method_has_arguments!("reorder", args)
spawn.reorder!(*args)
end
@@ -322,7 +322,7 @@ module ActiveRecord
# User.joins("LEFT JOIN bookmarks ON bookmarks.bookmarkable_type = 'Post' AND bookmarks.user_id = users.id")
# => SELECT "users".* FROM "users" LEFT JOIN bookmarks ON bookmarks.bookmarkable_type = 'Post' AND bookmarks.user_id = users.id
def joins(*args)
- has_arguments?("joins", args)
+ check_if_method_has_arguments!("joins", args)
spawn.joins!(*args.compact.flatten)
end
@@ -935,10 +935,10 @@ module ActiveRecord
# passed into that method as an input. For example:
#
# def references(*args)
- # has_arguments?("references", args)
+ # check_if_method_has_arguments!("references", args)
# ...
# end
- def has_arguments?(method_name, args)
+ def check_if_method_has_arguments!(method_name, args)
if args.blank?
raise ArgumentError, "The method .#{method_name}() must contain arguments."
end