Skip to content

Instantly share code, notes, and snippets.

@lukesutton
Created October 22, 2008 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukesutton/18855 to your computer and use it in GitHub Desktop.
Save lukesutton/18855 to your computer and use it in GitHub Desktop.
class SalesTotals
include DataMapper::Resource
include DataMapper::Caching
property :id, Serial
property :sales, Integer
property :items, Integer
property :value, Money
property :start_at, Time
property :end_at, Time
calculate :sales do |records|
records.length
end
calculate :items do |records|
records.inject(0) do |memo, record|
memo += record.items.count
memo
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment