Sha256: 80fc0bd6ccf862ef2c3033ce07cc23168f32b8318388ce5a2d04896c0056111f
Contents?: true
Size: 922 Bytes
Versions: 3
Compression:
Stored size: 922 Bytes
Contents
require 'fileutils' class FileHelper def initialize @temp_folders = [] end def create_temp_folder folder_name = "#{ENV['TMP'].gsub('\\', '/')}/#{timestamp}" @temp_folders << folder_name Dir.mkdir folder_name folder_name end def remove_temp_folders @temp_folders.each do |folder_name| FileUtils.rm_rf folder_name end end def create_temp_file(folder, content) file_name = "#{folder}/file #{timestamp}.txt" write_file file_name, content file_name end def write_file(file_name, content) Dir.mkdir File.dirname(file_name) unless Dir.exist? File.dirname(file_name) File.open(file_name, 'w') { |f| f.puts content } end def read_file(file_name) File.open(file_name, 'r') { |f| f.readlines.join("\n").strip } end private def timestamp sleep(0.01) (Time.now.to_f * 1000).to_i end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
active_git-0.0.3 | spec/support/helpers/file_helper.rb |
active_git-0.0.2 | spec/support/helpers/file_helper.rb |
active_git-0.0.1 | spec/support/helpers/file_helper.rb |