jumpstart 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/config/jumpstart_version.yml +1 -1
- data/lib/jumpstart/filetools.rb +8 -2
- data/test/jumpstart/test_filetools.rb +16 -0
- metadata +2 -2
data/lib/jumpstart/filetools.rb
CHANGED
@@ -125,18 +125,24 @@ module JumpStart::FileTools
|
|
125
125
|
def replace_strings(target_file, args)
|
126
126
|
if File.file?(target_file)
|
127
127
|
txt = IO.read(target_file)
|
128
|
+
old_dir = target_file.sub(/\/\w+\.*\w*$/, '')
|
128
129
|
new_file = target_file.dup
|
129
130
|
args.each do |x, y|
|
130
131
|
txt.gsub!(/#{x.to_s.upcase}_CLASS/, y.capitalize)
|
131
132
|
txt.gsub!(/#{x.to_s.upcase}/, y)
|
132
133
|
new_file.gsub!(/#{x.to_s.downcase}/, y)
|
133
134
|
end
|
134
|
-
|
135
|
-
FileUtils.mkdir_p(
|
135
|
+
new_dir = new_file.sub(/\/\w+\.*\w*$/, '')
|
136
|
+
FileUtils.mkdir_p(new_dir)
|
136
137
|
FileUtils.rm(target_file)
|
137
138
|
File.open(new_file, "w") do |file|
|
138
139
|
file.puts txt
|
139
140
|
end
|
141
|
+
if File.directory?(old_dir)
|
142
|
+
if (Dir.entries(old_dir) - JumpStart::IGNORE_DIRS).empty?
|
143
|
+
FileUtils.remove_dir(old_dir)
|
144
|
+
end
|
145
|
+
end
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
@@ -243,6 +243,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
243
243
|
@target_files = []
|
244
244
|
@target_files << @target_file_1 << @target_file_2 << @target_file_3
|
245
245
|
@source_file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb")
|
246
|
+
FileUtils.mkdir_p("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
|
246
247
|
@target_files.each do |x|
|
247
248
|
File.open(x, 'w+') do |file|
|
248
249
|
file.puts @source_file
|
@@ -258,6 +259,9 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
258
259
|
if File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle")
|
259
260
|
FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle")
|
260
261
|
end
|
262
|
+
if File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
|
263
|
+
FileUtils.remove_dir("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
|
264
|
+
end
|
261
265
|
end
|
262
266
|
|
263
267
|
should "replace strings with replace_strings method if the path does not contain the replacement strings and only one replacement string is provided" do
|
@@ -306,6 +310,18 @@ class TestJumpstartFileTools < Test::Unit::TestCase
|
|
306
310
|
assert File.exists?(@new_file_3)
|
307
311
|
assert !File.exists?(@target_file_3)
|
308
312
|
end
|
313
|
+
|
314
|
+
should "remove old dirs when empty after string replacement" do
|
315
|
+
FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
|
316
|
+
assert !File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
|
317
|
+
end
|
318
|
+
|
319
|
+
should "not remove old dirs after string replacement if they are not empty" do
|
320
|
+
FileUtils.touch("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name/another_file.txt")
|
321
|
+
FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
|
322
|
+
assert File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
|
323
|
+
assert File.exists?(@new_file_3)
|
324
|
+
end
|
309
325
|
|
310
326
|
end
|
311
327
|
|