diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2013-12-05 12:20:03 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2013-12-06 08:53:14 -0500 |
commit | 0aad463cfbe9853fd3a7ab0f8e4e0a34715fd62c (patch) | |
tree | 8bce8bc45b85355d01657e67d1152f6f41fbb971 /activerecord/lib/active_record/relation | |
parent | 5086c8c2113b67eb893cb34882e06c8b83e7951c (diff) | |
download | rails-0aad463cfbe9853fd3a7ab0f8e4e0a34715fd62c.tar.gz rails-0aad463cfbe9853fd3a7ab0f8e4e0a34715fd62c.tar.bz2 rails-0aad463cfbe9853fd3a7ab0f8e4e0a34715fd62c.zip |
`find_in_batches` now returns an `Enumerator` when called without a block, so that it
can be chained with other `Enumerable` methods.
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 9 |
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 49b01909c6..87d6f12aa5 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 + # # ==== Options # * <tt>:batch_size</tt> - Specifies the size of the batch. Default to 1000. # * <tt>:start</tt> - Specifies the starting point for the batch processing. @@ -86,6 +94,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 |