Module: Kitchen::Docker::Helpers::FileHelper

Included in:
Container
Defined in:
lib/kitchen/docker/helpers/file_helper.rb

Instance Method Summary collapse

Instance Method Details

#create_temp_file(file, contents) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kitchen/docker/helpers/file_helper.rb', line 20

def create_temp_file(file, contents)
  debug("[Docker] Creating temp file #{file}")
  debug('[Docker] --- Start Temp File Contents ---')
  debug(contents)
  debug('[Docker] --- End Temp File Contents ---')

  begin
    path = ::File.dirname(file)
    ::FileUtils.mkdir_p(path) unless ::Dir.exist?(path)
    file = ::File.open(file, 'w')
    file.write(contents)
  rescue IOError => e
    raise "Failed to write temp file. Error Details: #{e}"
  ensure
    file.close unless file.nil?
  end
end