Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make explicit the method will raise an exception

Taking the wise advice of @carlosantoniodasilva
  • Loading branch information...
commit 5cbee323aa14c761a7651113f4282be4ec2d0e7f 1 parent 1509844
@rafaelfranca rafaelfranca authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 activerecord/lib/active_record/relation/query_methods.rb
View
20 activerecord/lib/active_record/relation/query_methods.rb
@@ -112,7 +112,7 @@ def create_with_value # :nodoc:
#
# 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 @@ def includes!(*args) # :nodoc:
# 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 @@ def eager_load!(*args) # :nodoc:
# 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 @@ def preload!(*args) # :nodoc:
# 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 @@ def select!(*fields) # :nodoc:
# 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 @@ def group!(*args) # :nodoc:
# 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 @@ def order!(*args) # :nodoc:
#
# 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 @@ def reorder!(*args) # :nodoc:
# 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 @@ def validate_order_args(args)
# 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
Please sign in to comment.
Something went wrong with that request. Please try again.