New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sized enumerator #13938

Merged
merged 6 commits into from Feb 5, 2014

Conversation

Projects
None yet
2 participants
@marcandre
Contributor

marcandre commented Feb 4, 2014

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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Feb 4, 2014

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.

Member

rafaelfranca commented Feb 4, 2014

@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

This comment has been minimized.

Show comment
Hide comment
@marcandre

marcandre Feb 5, 2014

Contributor

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

Contributor

marcandre commented Feb 5, 2014

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

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Feb 5, 2014

Member

Thanks.

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

Member

rafaelfranca commented Feb 5, 2014

Thanks.

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

rafaelfranca added a commit that referenced this pull request Feb 5, 2014

@rafaelfranca rafaelfranca merged commit 84fe7b7 into rails:master Feb 5, 2014

1 check was pending

default The Travis CI build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment