1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 00:15:58 +01:00

Module generator finishes for partially existing files

This resolves #219. When generating a new module, if all the files to
generate already exist then it fails as before. If some of the files
already exist, then the files that need to be created are created. Any
existing files are not changed.

Also added a bunch of tests for this feature via rspec. Run them from
the test folder with `rake spec`.
This commit is contained in:
Matt Chernosky
2016-11-29 23:19:52 -07:00
parent 8e31f5d869
commit 7b51355e5a
4 changed files with 180 additions and 4 deletions

View File

@@ -187,14 +187,24 @@ class UnityModuleGenerator
files = files_to_operate_on(module_name, pattern)
#Abort if any module already exists
#Abort if all of the module files already exist
all_files_exist = true
files.each do |file|
raise "ERROR: File #{file[:name]} already exists. Exiting." if File.exist?(file[:path])
if not File.exist?(file[:path])
all_files_exist = false
end
end
raise "ERROR: File #{files[0][:name]} already exists. Exiting." if all_files_exist
# Create Source Modules
files.each_with_index do |file, i|
FileUtils.mkdir_p(File.dirname(file[:path]), :verbose => false) # Create the path first if necessary.
# If this file already exists, don't overwrite it.
if File.exist?(file[:path])
puts "File #{file[:path]} already exists!"
next
end
# Create the path first if necessary.
FileUtils.mkdir_p(File.dirname(file[:path]), :verbose => false)
File.open(file[:path], 'w') do |f|
f.write("#{file[:boilerplate]}\n" % [file[:name]]) unless file[:boilerplate].nil?
f.write(file[:template] % [ file[:name],