class Fasten::StdThreadProxy

Attributes

fasten_original[R]

Public Class Methods

new(fasten_original) click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 5
def initialize(fasten_original)
  @fasten_original = fasten_original
end

Private Class Methods

install() click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 29
def install
  return if @installed

  oldverbose = $VERBOSE
  $VERBOSE = nil

  Object.const_set :STDOUT, StdThreadProxy.new(STDOUT) # rubocop:disable Style/GlobalStdStream
  Object.const_set :STDERR, StdThreadProxy.new(STDERR) # rubocop:disable Style/GlobalStdStream

  $stdout = StdThreadProxy.new $stdout
  $stderr = StdThreadProxy.new $stderr

  @installed = true
ensure
  $VERBOSE = oldverbose
end
thread_io() click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 50
def thread_io
  Thread.current[:FASTEN_STD_THREAD_PROXY]
end
thread_io=(io) click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 46
def thread_io=(io)
  Thread.current[:FASTEN_STD_THREAD_PROXY] = io
end
uninstall() click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 54
def uninstall
  return unless @installed

  oldverbose = $VERBOSE
  $VERBOSE = nil

  Object.const_set :STDOUT, STDOUT.fasten_original if STDOUT.is_a? StdThreadProxy # rubocop:disable Style/GlobalStdStream
  Object.const_set :STDERR, STDERR.fasten_original if STDERR.is_a? StdThreadProxy # rubocop:disable Style/GlobalStdStream

  $stdout = $stdout.fasten_original if $stdout.is_a? StdThreadProxy
  $stderr = $stderr.fasten_original if $stderr.is_a? StdThreadProxy

  @installed = nil
ensure
  $VERBOSE = oldverbose
end

Public Instance Methods

respond_to?(*args) click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 9
def respond_to?(*args)
  target = Thread.current[:FASTEN_STD_THREAD_PROXY] || @fasten_original
  target.send :respond_to?, *args
end

Private Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 21
def method_missing(method, *args, &block)
  target = Thread.current[:FASTEN_STD_THREAD_PROXY] || @fasten_original
  target.send method, *args, &block
rescue StandardError => e
  raise e
end
respond_to_missing?(*args) click to toggle source
# File lib/fasten/std_thread_proxy.rb, line 16
def respond_to_missing?(*args)
  target = Thread.current[:FASTEN_STD_THREAD_PROXY] || @fasten_original
  target.send :respond_to_missing?, *args
end