Created
March 8, 2012 12:17
-
-
Save brianwebb01/2000752 to your computer and use it in GitHub Desktop.
Convert existing rails migration code to new script/generate command
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
data = <<EODATA | |
t.string :physical_address | |
t.string :physical_address2 | |
t.string :physical_city | |
t.integer :physical_state_id | |
t.string :physical_postal_code | |
t.integer :physical_country_id | |
t.string :billing_address | |
t.string :billing_address2 | |
t.string :billing_city | |
t.integer :billing_state_id | |
t.string :billing_postal_code | |
t.integer :billing_country_id | |
EODATA | |
results = data.scan(/\s*t.(string|boolean|integer|text|date|datetime)\s+:(\w*),*/i) | |
params = [] | |
string = "script/generate scaffold MyCoolModel " | |
results.each do |match| | |
params << "#{match.last}:#{match.first}" | |
end | |
string += params.join(' ') | |
puts string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment