Class: Pal::Common::LocalFileUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/pal/common/local_file_utils.rb

Class Method Summary collapse

Class Method Details

.clean_dir(path) ⇒ Object



18
19
20
21
22
# File 'lib/pal/common/local_file_utils.rb', line 18

def self.clean_dir(path)
  dir = File.dirname(path)

  FileUtils.rm_rf(dir) if File.directory?(dir)
end

.read_file(file_location) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/pal/common/local_file_utils.rb', line 28

def self.read_file(file_location)
  result = file_location.start_with?("/") ? file_location : File.join(File.dirname(__FILE__), file_location)

  raise "No file found at [#{result}]" unless File.exist? result

  File.read(result)
end

.remove_file(path_to_file) ⇒ Object



24
25
26
# File 'lib/pal/common/local_file_utils.rb', line 24

def self.remove_file(path_to_file)
  File.delete(path_to_file) if File.exist?(path_to_file)
end

.with_file(path, extension, &block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/pal/common/local_file_utils.rb', line 9

def self.with_file(path, extension, &block)
  dir = File.dirname(path)

  FileUtils.mkdir_p(dir) unless File.directory?(dir)

  path << ".#{extension}"
  File.open(path, "w", &block)
end