mongoid/moped — pull request #238 by fancyremarker (2013-11-27 17:03:37+00:00)
Title: Add @cache to Moped::Cursor for out-of-block iteration

*Caveat: This is potentially very risky, so feel free to reject.* I'm not familiar enough with Mongoid to understand all the implications of this change. That said, we've been using it in production for some time without any apparent ill effects.

The Mongo Ruby driver (and thus Mongoid 2.x) supported iterating over a cursor outside a block, using such operations as take(). For example:

```ruby
batch_size = 10
cursor = session[:users].find.cursor
while (users = cursor.take(batch_size)).present?
# Do stuff...
end
# Do more stuff...
```

This was a convenient pattern for implementing lots of algorithms in a more readable way than if they were written using each(). This patch reintroduces this convenience.

cc: @dblock