Sha256: 4f38597a6c5660f10b237b68e914f1f85d7ead1dde37c7f0ec7ee829be0457bb

Contents?: true

Size: 903 Bytes

Versions: 7

Compression:

Stored size: 903 Bytes

Contents

namespace :proto do
  desc 'Creates a new migration'
  task :migration, :directory, :name do |task, args|
    require File.expand_path('../../../zen', __FILE__)
    require 'fileutils'

    # Validate the input
    if !args[:directory]
      abort 'You need to specify a directory for the migration.'
    end

    if !args[:name]
      abort 'You need to specify a name for the migration.'
    end

    if !File.directory?(args[:directory])
      abort "The directory #{args[:directory]} doesn't exist."
    end

    proto_path = File.expand_path('../../../../proto/migration.rb', __FILE__)
    new_path   = File.join(args[:directory], "#{Time.new.to_i}_#{args[:name]}.rb")

    # Copy the prototype to the location
    begin
      FileUtils.cp(proto_path, new_path)
      puts "Migration saved in #{new_path}"
    rescue => e
      puts "Failed to create the migration: #{e.message}"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zen-0.4.3 lib/zen/task/proto.rake
zen-0.4.2 lib/zen/task/proto.rake
zen-0.4.1 lib/zen/task/proto.rake
zen-0.4 lib/zen/task/proto.rake
zen-0.3 lib/zen/task/proto.rake
zen-0.3b1 lib/zen/task/proto.rake
zen-0.3b lib/zen/task/proto.rake