Class: Dhalang::FileUtils
- Inherits:
-
Object
- Object
- Dhalang::FileUtils
- Defined in:
- lib/Dhalang/file_utils.rb
Overview
Contains common logic for files.
Class Method Summary collapse
-
.create_temp_file(extension, content = nil) ⇒ Tempfile
Creates a new temp file.
-
.delete(file) ⇒ Object
Deletes the given file.
-
.read_binary(file_path) ⇒ String
Reads the file under the given filepath as a binary.
Class Method Details
.create_temp_file(extension, content = nil) ⇒ Tempfile
Creates a new 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.
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.
10 11 12 |
# File 'lib/Dhalang/file_utils.rb', line 10 def self.read_binary(file_path) IO.binread(file_path) end |