Created
May 5, 2014 06:38
-
-
Save scottharvey/284c824858f14e06ee74 to your computer and use it in GitHub Desktop.
DSL for FlattenRecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DenormalizedOrder | |
include FlattenRecord::Denormalize | |
denormalize { | |
except: [:updated_at], | |
methods: [:grand_total, :average_price], | |
include: { | |
line_items: { | |
only: [:quantity, :price] | |
include: [:item] | |
}, | |
customer: [] | |
} | |
} | |
def average_price(order) | |
order.line_items.map(&:price) / order.lines_items.size | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment