class RackConsole::OutputCapture

Public Class Methods

new() click to toggle source
# File lib/rack_console/output_capture.rb, line 5
def initialize
  @old = $stdout
  @io = ::StringIO.new
  @main_thread = ::Thread.current
end

Public Instance Methods

capture() { || ... } click to toggle source
# File lib/rack_console/output_capture.rb, line 15
def capture
  $stdout = self
  yield
ensure
  $stdout = @old
end
output() click to toggle source
# File lib/rack_console/output_capture.rb, line 22
def output
  @io.rewind
  @io.read
end
write(value) click to toggle source
# File lib/rack_console/output_capture.rb, line 11
def write(value)
  io.write(value)
end

Private Instance Methods

io() click to toggle source
# File lib/rack_console/output_capture.rb, line 29
def io
  ::Thread.current == @main_thread || @main_thread[:rack_console_capture_all] ? @io : @old
end