module Mumukit::WithTempfile

Public Instance Methods

create_tempfile() click to toggle source
# File lib/mumukit/with_tempfile.rb, line 6
def create_tempfile
  Tempfile.new(['mumuki.compile', tempfile_extension])
end
mask_tempfile_references(string, masked_tempfile_path) click to toggle source
# File lib/mumukit/with_tempfile.rb, line 34
def mask_tempfile_references(string, masked_tempfile_path)
  string.gsub(/\/tmp\/mumuki\.compile(.+?)#{tempfile_extension}/, masked_tempfile_path)
end
tempfile_extension() click to toggle source
# File lib/mumukit/with_tempfile.rb, line 10
def tempfile_extension
  ''
end
with_tempfile() { |file| ... } click to toggle source
# File lib/mumukit/with_tempfile.rb, line 27
def with_tempfile
  file = create_tempfile
  yield file
  file.close
  file
end
write_tempdir!(files) click to toggle source
# File lib/mumukit/with_tempfile.rb, line 20
def write_tempdir!(files)
  dir = Dir.mktmpdir
  files.map do |filename, content|
    File.open("#{dir}/#{filename.sanitize_as_filename}", 'w') { |file| file.write content; file }
  end.try { |it| struct dir: dir, files: it }
end
write_tempfile!(content) click to toggle source
# File lib/mumukit/with_tempfile.rb, line 14
def write_tempfile!(content)
  with_tempfile do |file|
    file.write(content)
  end
end