Module: TaliaCore::DataTypes::TempFileHandling::ClassMethods

Included in:
FileRecord
Defined in:
lib/talia_core/data_types/temp_file_handling.rb

Instance Method Summary collapse

Instance Method Details

#copy_to_temp_file(file, temp_base_name) ⇒ Object

Copies the given file path to a new tempfile, returning the closed tempfile.



12
13
14
15
16
17
18
# File 'lib/talia_core/data_types/temp_file_handling.rb', line 12

def copy_to_temp_file(file, temp_base_name)
  create_tempfile_path
  returning Tempfile.new(temp_base_name, self.tempfile_path) do |tmp|
    tmp.close
    FileUtils.cp file, tmp.path
  end
end

#create_tempfile_pathObject



30
31
32
# File 'lib/talia_core/data_types/temp_file_handling.rb', line 30

def create_tempfile_path
  FileUtils.mkdir_p(tempfile_path) unless File.exists?(tempfile_path)
end

#write_to_temp_file(data, filename) ⇒ Object

Writes the given data to a new tempfile, returning the closed tempfile.



21
22
23
24
25
26
27
28
# File 'lib/talia_core/data_types/temp_file_handling.rb', line 21

def write_to_temp_file(data, filename)
  create_tempfile_path
  returning Tempfile.new(filename, self.tempfile_path) do |tmp|
    tmp.binmode
    tmp.write data
    tmp.close
  end
end