Class: Shellfie::OutputWriter
- Inherits:
-
Object
- Object
- Shellfie::OutputWriter
- Defined in:
- lib/shellfie/output_writer.rb
Class Method Summary collapse
Class Method Details
.write(path, extension:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shellfie/output_writer.rb', line 10 def write(path, extension:) FileUtils.mkdir_p(output_directory(path)) unless stdout?(path) temp = Tempfile.new(["shellfie", ".#{extension}"], output_directory(path), binmode: true) temp.close yield temp.path return File.binread(temp.path) if stdout?(path) FileUtils.mv(temp.path, path) path ensure if temp temp.close unless temp.closed? File.delete(temp.path) if File.exist?(temp.path) end end |