Module: Mumukit::WithTempfile

Included in:
Templates::FileHook
Defined in:
lib/mumukit/with_tempfile.rb

Instance Method Summary collapse

Instance Method Details

#create_tempfileObject



5
6
7
# File 'lib/mumukit/with_tempfile.rb', line 5

def create_tempfile
  Tempfile.new(['mumuki.compile', tempfile_extension])
end

#tempfile_extensionObject



9
10
11
# File 'lib/mumukit/with_tempfile.rb', line 9

def tempfile_extension
  ''
end

#with_tempfile {|file| ... } ⇒ Object

Yields:

  • (file)


19
20
21
22
23
24
# File 'lib/mumukit/with_tempfile.rb', line 19

def with_tempfile
  file = create_tempfile
  yield file
  file.close
  file
end

#write_tempfile!(content) ⇒ Object



13
14
15
16
17
# File 'lib/mumukit/with_tempfile.rb', line 13

def write_tempfile!(content)
  with_tempfile do |file|
    file.write(content)
  end
end