Module: Common::FileHelpers

Defined in:
lib/common/file_helpers.rb

Class Method Summary collapse

Class Method Details

.delete_file_if_exists(path) ⇒ Object



7
8
9
# File 'lib/common/file_helpers.rb', line 7

def delete_file_if_exists(path)
  File.delete(path) if File.exist?(path)
end

.generate_temp_file(file_body, file_name = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/common/file_helpers.rb', line 15

def generate_temp_file(file_body, file_name = nil)
  file_name = SecureRandom.hex if file_name.nil?
  file_path = "tmp/#{file_name}"

  File.open(file_path, 'wb') do |file|
    file.write(file_body)
  end

  file_path
end

.random_file_pathObject



11
12
13
# File 'lib/common/file_helpers.rb', line 11

def random_file_path
  "tmp/#{SecureRandom.hex}"
end