aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-05-20 12:36:16 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-05-20 12:36:16 +0900
commit0d874b4a5a39646bbfc3e062db62a3b3ab68b47c (patch)
tree1c0862461d37e032006573b94abe7ee5cbddfae9 /activerecord/lib/active_record
parentc01ea3e54984f8ecc698af4a701483b560d616aa (diff)
downloadrails-0d874b4a5a39646bbfc3e062db62a3b3ab68b47c.tar.gz
rails-0d874b4a5a39646bbfc3e062db62a3b3ab68b47c.tar.bz2
rails-0d874b4a5a39646bbfc3e062db62a3b3ab68b47c.zip
Make `VALID_DIRECTIONS` to `Set`
```ruby require "benchmark/ips" require "set" array = [:asc, :desc, :ASC, :DESC, "asc", "desc", "ASC", "DESC"] set = array.to_set item = "DESC" Benchmark.ips do |x| x.report "array" do array.include?(item) end x.report "set" do set.include?(item) end end ``` ``` % ruby array_vs_set.rb Warming up -------------------------------------- array 188.441k i/100ms set 229.531k i/100ms Calculating ------------------------------------- array 3.508M (± 9.0%) i/s - 17.525M in 5.043058s set 5.134M (± 7.6%) i/s - 25.707M in 5.038921s ```
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 76e529f2de..79e65baae5 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -1100,14 +1100,16 @@ module ActiveRecord
end
VALID_DIRECTIONS = [:asc, :desc, :ASC, :DESC,
- "asc", "desc", "ASC", "DESC"] # :nodoc:
+ "asc", "desc", "ASC", "DESC"].to_set # :nodoc:
def validate_order_args(args)
args.each do |arg|
next unless arg.is_a?(Hash)
arg.each do |_key, value|
- raise ArgumentError, "Direction \"#{value}\" is invalid. Valid " \
- "directions are: #{VALID_DIRECTIONS.inspect}" unless VALID_DIRECTIONS.include?(value)
+ unless VALID_DIRECTIONS.include?(value)
+ raise ArgumentError,
+ "Direction \"#{value}\" is invalid. Valid directions are: #{VALID_DIRECTIONS.to_a.inspect}"
+ end
end
end
end