Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created August 16, 2010 17:17
Show Gist options
  • Save jnunemaker/527321 to your computer and use it in GitHub Desktop.
Save jnunemaker/527321 to your computer and use it in GitHub Desktop.
A way of making map/reduce queries using a class
module PageViewsByMonth
def map
<<-MAP
function() {…}
MAP
end
def reduce
<<-REDUCE
function() {…}
REDUCE
end
def build
Views.collection.map_reduce(map, reduce)
end
extend self
end
# Usage: PageViewsByMonth.build
@jnunemaker
Copy link
Author

I like this idea because it separates out the map and reduce quite nicely so you can see what is going on without muddling your models.

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