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