From a4b8ca08099ac60732e4ae3660d50a1e22284383 Mon Sep 17 00:00:00 2001 From: Nilesh Mamidi Date: Wed, 2 May 2018 15:57:07 +0530 Subject: [PATCH 1/2] Multipe task with same name Having multiple task with same name, created at different time, produces a bug. It creates multiple entries of version in task_recorder. they above code will check, whether similar file exists or not --- lib/generators/task/task_generator.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/generators/task/task_generator.rb b/lib/generators/task/task_generator.rb index adfc69d..ed1bc9d 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( + file_names = Dir[FILE_MASK].collect{ |f| AfterParty::TaskRecorder.new(f) }.map {|f| "#{f.task_name}"} + 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 From f8f3a4430c24bf1ba7e3a9afbb803922f6743943 Mon Sep 17 00:00:00 2001 From: Steve Mitchell Date: Sun, 1 Dec 2024 11:26:05 -0500 Subject: [PATCH 2/2] lints --- lib/generators/task/task_generator.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/generators/task/task_generator.rb b/lib/generators/task/task_generator.rb index ed1bc9d..46f8e5b 100644 --- a/lib/generators/task/task_generator.rb +++ b/lib/generators/task/task_generator.rb @@ -6,7 +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") + FILE_MASK = File.join(Rails.root, 'lib/tasks/deployment/*.rake') source_root(File.expand_path('templates', __dir__)) argument(:name, type: :string) class_option( @@ -16,15 +16,15 @@ class TaskGenerator < Rails::Generators::Base ) def copy_deploy_task - file_names = Dir[FILE_MASK].collect{ |f| AfterParty::TaskRecorder.new(f) }.map {|f| "#{f.task_name}"} + 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" + puts 'Error: Please Create a unique task name' else template( - 'deploy.txt.erb', - "lib/tasks/deployment/#{timestamp}_#{file_name}.rake" + 'deploy.txt.erb', + "lib/tasks/deployment/#{timestamp}_#{file_name}.rake" ) - end + end end private