Skip to content

Instantly share code, notes, and snippets.

@xrl
Created December 4, 2014 00:52
Show Gist options
  • Save xrl/d2378778517c0801ede0 to your computer and use it in GitHub Desktop.
Save xrl/d2378778517c0801ede0 to your computer and use it in GitHub Desktop.
def lookup(type)
case type
when "string" then "string"
when "text" then "string"
when "boolean" then "boolean"
when "integer" then "number"
when "datetime" then "utc"
else raise "don't know corresponding type for ActiveRecord #{type}"
end
end
def convert_to_ds_attrs(schema_blob)
schema_blob.lines.collect do |line|
case line
when /t.(\w+)\s+"(\w+)"/
type = lookup($1)
"#{$2}: DS.attr('#{type}')"
end
end
end
list = convert_to_ds_attrs(%Q{
t.string "plan_name"
t.string "ein"
t.string "plan_number"
t.boolean "complete"
t.integer "plan_sponsor_id"
t.integer "record_keeper_id"
t.integer "criteria_weightings_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.integer "step", default: 0
t.integer "criteria_weighting_id"
t.string "plan_profile_type"
t.text "plan_profile_raw_paste"
t.text "plan_profile_custom"
t.integer "participant_count", default: 0
t.datetime "completed_at"
t.string "api_key"
t.text "pdf_path"
})
print list.select{|x| x}.collect{|x| " "+x}.join(",\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment