5 # Utility functions for classes that use commands to postprocess
7 module CommandPostProcessor
10 # Encodes a string so that it is safe for use as a shell argument
11 def shell_encode string
12 '"' + string.gsub(/([\\`"$\n])/, "\\\\\\1") + '"'
15 # Creates a temporary file and returns its name
16 def tempfile extension, base = nil
17 base = self.class.name unless base
18 file = Tempfile.open(basename + extension)
24 # Writes the contents of the named file to an IO handle
25 def write_file_to_io filename, io
26 File.open(filename) { |file| io.write(file.read) }