Skip to content

Commit

Permalink
fix bug in new_migration
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Mar 31, 2010
1 parent 6bddd50 commit 41c2018
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions lib/tasks/standalone_migrations.rb
Expand Up @@ -65,20 +65,12 @@

desc "Create a new migration"
task :new_migration do |t|
unless ENV['name']
unless migration = ENV['name']
puts "Error: must provide name of migration to generate."
puts "For example: rake #{t.name} name=add_field_to_form"
exit 1
end

underscore = lambda{|camel_cased_word|
camel_cased_word.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
}

class_name = migration.split('_').map{|s| s.capitalize }.join
file_contents = <<eof
class #{class_name} < ActiveRecord::Migration
Expand All @@ -91,7 +83,6 @@ def self.down
end
eof

migration = underscore.call( ENV['name'] )
FileUtils.mkdir_p(options[:migrations]) unless File.exist?(options[:migrations])
file_name = "#{options[:migrations]}/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{migration}.rb"

Expand Down

0 comments on commit 41c2018

Please sign in to comment.