Class: Dhalang::FileUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/Dhalang/file_utils.rb

Overview

Contains common logic for files.

Class Method Summary collapse

Class Method Details

.create_temp_file(extension, content = nil) ⇒ Tempfile

Creates a new temp file.

Parameters:

  • extension (String)

    The extension of the file.

  • content (String) (defaults to: nil)

    The content of the file. (Optional)

Returns:

  • (Tempfile)

    The created temp file.



20
21
22
23
24
25
26
27
# File 'lib/Dhalang/file_utils.rb', line 20

def self.create_temp_file(extension, content = nil)
    temp_file = Tempfile.new(["dhalang",".#{extension}"])
    unless(content == nil)
        temp_file.write(content)
        temp_file.rewind
    end
    temp_file
end

.delete(file) ⇒ Object

Deletes the given file.

Parameters:

  • file (File)

    The file to delete.



32
33
34
35
# File 'lib/Dhalang/file_utils.rb', line 32

def self.delete(file)
    file.close unless file.closed?
    file.unlink
end

.read_binary(file_path) ⇒ String

Reads the file under the given filepath as a binary.

Parameters:

  • file_path (String)

    The absolute path of the file to read.

Returns:

  • (String)

    The binary content under the file_path.



10
11
12
# File 'lib/Dhalang/file_utils.rb', line 10

def self.read_binary(file_path)
    IO.binread(file_path)
end