namespace :g do desc "Create migration" task :migration, [:name] do |t, args| if args[:name].nil? raise "Please provide a name for migration (rake 'g:migration[my_file_name]')" end date_part = Time.now.strftime("%Y%m%d%H%M%S") words_part = args[:name].to_s.split(/(?=[A-Z])/).map(&:downcase).join("_") filename = "#{date_part}_#{words_part}.rb" full_filename = File.join("db", "migrate", filename) File.open(full_filename, "w") do |file| file.puts("Sequel.migration do") file.puts(" change do") file.puts(" end") file.puts("end") end end end