aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-06 17:03:37 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-06 17:05:19 -0200
commitf4e8d67367c7670ac5bbc75f001cd5c2b2deed30 (patch)
tree02fa8dbe6d9f1845d34670dc040541ccb67c3bdc /activerecord/lib/active_record/relation
parent101c19f55f5f1d86d35574b805278f11e9a1a48e (diff)
downloadrails-f4e8d67367c7670ac5bbc75f001cd5c2b2deed30.tar.gz
rails-f4e8d67367c7670ac5bbc75f001cd5c2b2deed30.tar.bz2
rails-f4e8d67367c7670ac5bbc75f001cd5c2b2deed30.zip
Use keyword argument in the find_in_batches API
We already validate the keys, so it is better to use the built-in feature to do this
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb18
1 files changed, 7 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index 4f0502ae75..9d690af11d 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -45,19 +45,19 @@ module ActiveRecord
#
# NOTE: You can't set the limit either, that's used to control
# the batch sizes.
- def find_each(options = {})
+ def find_each(start: nil, batch_size: 1000)
if block_given?
- find_in_batches(options) do |records|
+ find_in_batches(start: start, batch_size: batch_size) do |records|
records.each { |record| yield record }
end
else
- enum_for :find_each, options do
- options[:start] ? where(table[primary_key].gteq(options[:start])).size : size
+ enum_for(:find_each, start: start, batch_size: batch_size) do
+ start ? where(table[primary_key].gteq(start)).size : size
end
end
end
- # Yields each batch of records that was found by the find +options+ as
+ # Yields each batch of records that was found by the find options as
# an array.
#
# Person.where("age > 21").find_in_batches do |group|
@@ -95,15 +95,11 @@ module ActiveRecord
#
# NOTE: You can't set the limit either, that's used to control
# the batch sizes.
- def find_in_batches(options = {})
- options.assert_valid_keys(:start, :batch_size)
-
+ def find_in_batches(start: nil, batch_size: 1000)
relation = self
- start = options[:start]
- batch_size = options[:batch_size] || 1000
unless block_given?
- return to_enum(:find_in_batches, options) do
+ return to_enum(:find_in_batches, start: start, batch_size: batch_size) do
total = start ? where(table[primary_key].gteq(start)).size : size
(total - 1).div(batch_size) + 1
end