Created
February 3, 2014 16:41
-
-
Save elskwid/8787346 to your computer and use it in GitHub Desktop.
Attribute DSL for mapping csv columns to Virtus attributes
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
# Straight Virtus | |
attribute :invoice_date, DateTime, default: :_invoice_date | |
attribute :invoice_number, String, default: :_invoice_number | |
attribute :invoice_amount, RowParser::Attributes::Money, default: :_invoice_amount | |
attribute :invoice_currency_code, String, default: :_invoice_currency_code | |
# Connections DSL | |
# multiple attribute connections | |
connect_attributes do | |
invoice_date "invoice date", DateTime | |
invoice_number "invoice number", String | |
invoice_amount "invoice amount", Money | |
invoice_currency_code "invoice currency code", String | |
end | |
# or connect one at a time | |
connect "invoice date", :invoice_date, DateTime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool.
Declare me a heretic, but I think {} would be better than a do block here.
Where do defaults come from? naming convention?