Methods

Class Index [+]

Quicksearch

TaskJuggler::StdIoWrapper

This module provides just one method to run the passed block. It will capture all content that will be send to $stdout and $stderr by the block. I can also feed the String provided by stdIn to $stdin of the block.

Constants

Results

Public Instance Methods

stdIoWrapper(stdIn = nil) click to toggle source
    # File lib/taskjuggler/StdIoWrapper.rb, line 23
23:     def stdIoWrapper(stdIn = nil)
24:       # Save the old $stdout and $stderr and replace them with StringIO
25:       # objects to capture the output.
26:       oldStdOut = $stdout
27:       oldStdErr = $stderr
28:       $stdout = (out = StringIO.new)
29:       $stderr = (err = StringIO.new)
30: 
31:       # If the caller provided a String to feed into $stdin, we replace that
32:       # as well.
33:       if stdIn
34:         oldStdIn = $stdin
35:         $stdin = StringIO.new(stdIn)
36:       end
37: 
38:       begin
39:         # Call the block with the hooked up IOs.
40:         res = yield
41:       rescue RuntimeError
42:         # Blocks that are called this way usually return 0 on success and 1 on
43:         # errors.
44:         res = 1
45:       ensure
46:         # Restore the stdio channels no matter what.
47:         $stdout = oldStdOut
48:         $stderr = oldStdErr
49:         $stdin = oldStdIn if stdIn
50:       end
51: 
52:       # Return the return value of the block and the $stdout and $stderr
53:       # captures.
54:       Results.new(res, out.string, err.string)
55:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.