Module: Voodoo::CommandPostProcessor
- Included in:
- GasELFGenerator, NasmELFGenerator
- Defined in:
- lib/voodoo/generators/command_postprocessor.rb
Overview
Utility functions for classes that use commands to postprocess generator output.
Class Method Summary collapse
-
.shell_encode(string) ⇒ Object
Encodes a string so that it is safe for use as a shell argument.
-
.tempfile(extension, base = nil) ⇒ Object
Creates a temporary file and returns its name.
-
.write_file_to_io(filename, io) ⇒ Object
Writes the contents of the named file to an IO handle.
Class Method Details
.shell_encode(string) ⇒ Object
Encodes a string so that it is safe for use as a shell argument
11 12 13 |
# File 'lib/voodoo/generators/command_postprocessor.rb', line 11 def shell_encode string '"' + string.gsub(/([\\`"$\n])/, "\\\\\\1") + '"' end |
.tempfile(extension, base = nil) ⇒ Object
Creates a temporary file and returns its name
16 17 18 19 20 21 22 |
# File 'lib/voodoo/generators/command_postprocessor.rb', line 16 def tempfile extension, base = nil base = self.class.name unless base file = Tempfile.open(basename + extension) name = file.path file.close name end |
.write_file_to_io(filename, io) ⇒ Object
Writes the contents of the named file to an IO handle
25 26 27 |
# File 'lib/voodoo/generators/command_postprocessor.rb', line 25 def write_file_to_io filename, io File.open(filename) { |file| io.write(file.read) } end |