diff --git a/lib/generators/task/task_generator.rb b/lib/generators/task/task_generator.rb index adfc69d..46f8e5b 100644 --- a/lib/generators/task/task_generator.rb +++ b/lib/generators/task/task_generator.rb @@ -6,6 +6,7 @@ module AfterParty module Generators # creates after_party tasks class TaskGenerator < Rails::Generators::Base + FILE_MASK = File.join(Rails.root, 'lib/tasks/deployment/*.rake') source_root(File.expand_path('templates', __dir__)) argument(:name, type: :string) class_option( @@ -15,10 +16,15 @@ class TaskGenerator < Rails::Generators::Base ) def copy_deploy_task - template( - 'deploy.txt.erb', - "lib/tasks/deployment/#{timestamp}_#{file_name}.rake" - ) + file_names = Dir[FILE_MASK].collect { |f| AfterParty::TaskRecorder.new(f) }.map { |f| f.task_name.to_s } + if file_names.include?(file_name) + puts 'Error: Please Create a unique task name' + else + template( + 'deploy.txt.erb', + "lib/tasks/deployment/#{timestamp}_#{file_name}.rake" + ) + end end private