lib/reciper/helpers.rb in reciper-0.0.3 vs lib/reciper/helpers.rb in reciper-0.0.4
- old
+ new
@@ -2,21 +2,30 @@
module Reciper
class NoTestOutput < RuntimeError
end
+ class NoFileToBeOverriden < RuntimeError
+ end
+
module Helpers
def copy_file(filename, options={})
destination_dir = @ruby_app_path + "/" + (options[:to] || "")
unless File.directory?(destination_dir)
FileUtils.mkdir_p(destination_dir)
end
FileUtils.cp(@recipe_path + "/" + filename, destination_dir)
- @operations << [:copy, (options[:to] || "") + filename]
+ new_filename = options[:as] || filename
+
+ if(options[:as])
+ FileUtils.mv(destination_dir + "/" + filename, destination_dir + "/" + new_filename)
+ end
+
+ @operations << [:copy, (options[:to] || "") + new_filename]
end
def run_tests(options={})
Dir.chdir(@ruby_app_path) do
response = `bundle exec rspec spec`
@@ -69,10 +78,12 @@
File.open(@ruby_app_path + "/" + operation[1], "w") { |file| file.write(operation[2]) }
elsif operation[0] == :run_command
spawn(operation[1]) if operation[1]
Process.wait
+ elsif operation[0] == :override_file
+ FileUtils.cp(operation[1], @ruby_app_path + "/" + operation[2])
end
end
end
def run_command(command, rollback_command=nil)
@@ -86,8 +97,24 @@
@operations << [:run_command, rollback_command || nil]
true
else
false
end
+ end
+
+ def override_file(file, file_to_be_overriden)
+ Dir.chdir(@ruby_app_path) do
+ fail NoFileToBeOverriden unless File.exists?(file_to_be_overriden)
+
+ FileUtils.mkdir_p("/tmp/reciper")
+ filename = File.basename(file_to_be_overriden)
+ tmp_file = "/tmp/reciper/#{filename}"
+
+ FileUtils.cp(file_to_be_overriden, tmp_file)
+
+ @operations << [:override_file, tmp_file, file_to_be_overriden]
+ end
+
+ FileUtils.cp(@recipe_path + "/" + file, @ruby_app_path + "/" + file_to_be_overriden)
end
end
end
\ No newline at end of file