jgaskins / perpetuity

Persistence gem for Ruby objects using the Data Mapper pattern
http://jgaskins.org/blog/2012/04/20/data-mapper-vs-active-record/
MIT License
250 stars 14 forks source link

More Enumerable-like syntax #24

Closed jgaskins closed 11 years ago

jgaskins commented 11 years ago

We have a Mapper#select, which is great, but I think we can do even better.

Most of the rest of Enumerable can be done on the resulting array.

Both Mapper and Retrieval will need to implement this functionality. This raises a red flag in my mind and means we may need to merge the classes. Maybe merge the two classes so that using Enumerable methods just instantiates a new Mapper instead of a Retrieval?

The idea behind Retrieval was to represent a result set, but the result set is actually the array returned from Retrieval#to_a. The current implementation of Retrieval doesn't represent a query result at all; it's just query metadata.

I'll experiment with it a bit and see what I come up with.

jgaskins commented 11 years ago

Completed find, count, and reject as well as find_all and detect aliases while pairing with @kevinsjoberg. The diff.

map will not be implemented due to potential confusion about it yielding a database-query object, which may not work like an actual object in the collection.

jgaskins commented 11 years ago

Everything but min_by and max_by is implemented. Closing.