class StatSailr::Output::OutputMessage
Attributes
content[RW]
type[R]
Public Class Methods
new(type, content, parent)
click to toggle source
# File lib/statsailr/sts_output/output_manager.rb, line 12 def initialize(type, content, parent) @type = type @content = content @parent = parent if capture == false print @content end end
Public Instance Methods
run(stream) { || ... }
click to toggle source
# File lib/statsailr/sts_output/output_manager.rb, line 33 def run(stream) raise ArgumentError, 'missing block' unless block_given? if capture == false begin yield rescue => e raise e end else orig_stream = stream.dup IO.pipe do |r, w| # system call dup2() replaces the file descriptor stream.reopen(w) # there must be only one write end of the pipe; # otherwise the read end does not get an EOF # by the final `reopen` w.close # Now 'stream=$stdout' and 'r' are paired. orig_stream points to original stream(STDOUT). t = Thread.new { r.read } begin yield rescue => e raise e ensure stream.reopen orig_stream # restore file descriptor @content << t.value # join and get the result of the thread end end end end
set_content( content )
click to toggle source
# File lib/statsailr/sts_output/output_manager.rb, line 22 def set_content( content ) if capture == false print content end @content = content end
to_s()
click to toggle source
# File lib/statsailr/sts_output/output_manager.rb, line 29 def to_s return @content.to_s end