Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created February 3, 2014 16:41
Show Gist options
  • Save elskwid/8787346 to your computer and use it in GitHub Desktop.
Save elskwid/8787346 to your computer and use it in GitHub Desktop.
Attribute DSL for mapping csv columns to Virtus attributes
# 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
@supernullset
Copy link

Very cool.

Declare me a heretic, but I think {} would be better than a do block here.

Where do defaults come from? naming convention?

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