Module: TezosClient::Tools::TemporaryFile

Defined in:
lib/tezos_client/tools/temporary_file.rb

Class Method Summary collapse

Class Method Details

.with_file_copy(source_file_path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tezos_client/tools/temporary_file.rb', line 6

def self.with_file_copy(source_file_path)
  source_file = File.open(source_file_path, "r")
  source_extention = File.extname(source_file_path)

  file_copy_path = nil

  res = Tools::TemporaryFile.with_tempfile(source_extention) do |file_copy|
    file_copy.write(source_file.read)
    file_copy_path = file_copy.path
    file_copy.close
    yield(file_copy_path)
  end

  res
ensure
  File.delete(file_copy_path) if File.exist? file_copy_path
end

.with_tempfile(extension) ⇒ Object



24
25
26
27
28
29
# File 'lib/tezos_client/tools/temporary_file.rb', line 24

def self.with_tempfile(extension)
  file = Tempfile.new(["script", extension])
  yield(file)
ensure
  file.unlink
end