Sha256: 57db91e264343c59fac4b1a963791a74b785caca20dde852c8ec77e5d78e4df3

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

namespace :common_repository_model do
  task :prompt_for_area => :environment do
    require 'highline'
    highline = HighLine.new
    prompt_message = "Area Name to Create in Fedora:"
    @area_name = highline.ask(prompt_message)
    @verified_area_name = highline.ask("Verify #{prompt_message}")
  end
  task :validate_area_name => :environment do
    if @area_name.to_s.strip.size == 0
      message = "Area Name cannot be blank"
      $stderr.puts("\n\n\n#{message}\n\n\n")
      raise RuntimeError, message
    elsif @verified_area_name.to_s.strip.size == 0
      message = "Verified Area Name cannot be blank"
      $stderr.puts("\n\n\n#{message}\n\n\n")
      raise RuntimeError, message
    elsif @area_name != @verified_area_name
      message = "Area Name and Verified Area Name do not match:"
      message << "\n\t#{@area_name}\n\t#{@verified_area_name}"
      $stderr.puts("\n\n\n#{message}\n\n\n")
      raise RuntimeError, message
    end

  end
  desc "Create an Area in the CommonRepositoryModel.
        You will be prompted for a name"
  task :create_area => :environment do
    if ENV['AREA_NAME']
      @verified_area_name = @area_name = ENV['AREA_NAME']
      Rake::Task['common_repository_model:validate_area_name'].invoke
    else
      Rake::Task['common_repository_model:prompt_for_area'].invoke
      Rake::Task['common_repository_model:validate_area_name'].invoke
    end
    require 'common_repository_model/area'
    if area = CommonRepositoryModel::Area.find_by_name(@area_name)
      $stdout.puts(
        "\n\n\nArea Name #{@area_name} already exists as PID: #{area.pid}\n\n"
      )
    else
      area = CommonRepositoryModel::Area.new(name: @area_name)
      area.send(:save!)
      $stdout.puts(
        "\n\n\nCreated Area Name #{area.name.inspect} with PID: #{area.pid.inspect}\n\n"
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
common_repository_model-0.0.9 lib/tasks/common_repository_model.tasks
common_repository_model-0.0.8 lib/tasks/common_repository_model.tasks
common_repository_model-0.0.7 lib/tasks/common_repository_model.tasks
common_repository_model-0.0.6 lib/tasks/common_repository_model.tasks