Skip to content

Instantly share code, notes, and snippets.

@scottharvey
Created May 5, 2014 06:38
Show Gist options
  • Save scottharvey/284c824858f14e06ee74 to your computer and use it in GitHub Desktop.
Save scottharvey/284c824858f14e06ee74 to your computer and use it in GitHub Desktop.
DSL for FlattenRecord
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