require 'rubygems' require "dm-core" require 'dm-migrations' require '../lib/cheap_imports' DataMapper.setup(:default, 'sqlite3::memory:') class Cat include DataMapper::Resource property :id, Serial property :name, String property :age, Integer include CheapImports end class Appointment include DataMapper::Resource property :id, Serial property :cat_id, Integer property :starts_at, DateTime include CheapImports imports :legacy_data => { :starts_at => "APPOINTMENT START TIME", :starts_at_format => "%d %b %Y %H:%M", :cat_name => "ANIMAL IDENTIFIER" } end DataMapper.finalize DataMapper.auto_migrate! data = %{name\tage\nFluffy\t7} Import.import(Cat, data, {}, true) Cat.all.each do |c| puts c.inspect end data = %{ANIMAL IDENTIFIER,APPOINTMENT START TIME\n} data << %{Fluffy,5 Jan 2009 10:30\n} Import.import([Appointment], data) Appointment.all.each do |a| puts a.inspect end