aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-29 17:53:10 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-29 17:53:10 -0200
commitfec1028d088294c30f568e46db3bbd054a9330ff (patch)
tree93ee044f18873c3daa3acf86d338c6785b95e54a /activerecord/lib
parent2c964ac59194c340660986423b4aa93de447c37b (diff)
parent0aad463cfbe9853fd3a7ab0f8e4e0a34715fd62c (diff)
downloadrails-fec1028d088294c30f568e46db3bbd054a9330ff.tar.gz
rails-fec1028d088294c30f568e46db3bbd054a9330ff.tar.bz2
rails-fec1028d088294c30f568e46db3bbd054a9330ff.zip
Merge pull request #13201 from marcandre/find_in_batch_enumerator
`find_in_batches` now returns an `Enumerator` Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/batches.rb
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/batches.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb
index e98b4712f5..dfcfef2ad2 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -64,6 +64,14 @@ module ActiveRecord
# group.each { |person| person.party_all_night! }
# end
#
+ # If you do not provide a block to #find_in_batches, it will return an Enumerator
+ # for chaining with other methods:
+ #
+ # Person.find_in_batches.with_index do |group, batch|
+ # puts "Processing group ##{batch}"
+ # group.each(&:recover_from_last_night!)
+ # end
+ #
# To be yielded each record one by one, use #find_each instead.
#
# ==== Options
@@ -88,6 +96,7 @@ module ActiveRecord
# the batch sizes.
def find_in_batches(options = {})
options.assert_valid_keys(:start, :batch_size)
+ return to_enum(:find_in_batches, options) unless block_given?
relation = self