Skip to content

Sized enumerator - #13938

Merged
rafaelfranca merged 6 commits into
rails:masterfrom
marcandre:sized_enumerator
Feb 5, 2014
Merged

Sized enumerator#13938
rafaelfranca merged 6 commits into
rails:masterfrom
marcandre:sized_enumerator

Conversation

@marcandre

Copy link
Copy Markdown
Contributor

This PR adds a lazy size block to enumerators returned by Batches#find_each, find_in_batches, Result#each and Enumerable#index_by.

This allows, for example using my gem with_progress:

Users.where("balance > 0").find_each.with_progress do |u|
  UserMailer.send_invoice(u)
end

This will print a progress bar with an estimated time left, etc, while still loading the records in batches.

The PR also has a couple of test cleanup commits at the beginning.

Note: In Ruby 1.9, there is no Enumerator#size, so the test is conditional on that. The block given to to_enum is ignored in 1.9, so no specific treatment is needed.

@rafaelfranca

Copy link
Copy Markdown
Member

@marcandre seems good to me. Could you squash the commits that add the feature? The two obsolete removals commits are good as separated commits.

We will need a CHANGELOG entry too.

@marcandre

Copy link
Copy Markdown
Contributor Author

Right, forgot about the CHANGELOG, sorry. Done.
I feel the commits are independent and better left unsquashed. More detailed explanation here.

@rafaelfranca

Copy link
Copy Markdown
Member

Thanks.

About the squash it is fine to me. I agree with you that they are independent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants