class Cucumber::Formatter::Interceptor::Pipe
Attributes
Public Class Methods
Source
# File lib/cucumber/formatter/interceptor.rb, line 9 def initialize(pipe) @pipe = pipe @buffer = StringIO.new @wrapped = true @lock = Mutex.new end
Source
# File lib/cucumber/formatter/interceptor.rb, line 46 def self.unwrap!(pipe) validate_pipe pipe wrapped = nil case pipe when :stdout wrapped = $stdout $stdout = wrapped.unwrap! if $stdout.respond_to?(:unwrap!) when :stderr wrapped = $stderr $stderr = wrapped.unwrap! if $stderr.respond_to?(:unwrap!) end wrapped end
Source
# File lib/cucumber/formatter/interceptor.rb, line 42 def self.validate_pipe(pipe) raise ArgumentError, '#wrap only accepts :stderr or :stdout' unless %i[stdout stderr].include? pipe end
Source
# File lib/cucumber/formatter/interceptor.rb, line 60 def self.wrap(pipe) validate_pipe pipe case pipe when :stderr $stderr = new($stderr) $stderr when :stdout $stdout = new($stdout) $stdout end end
Public Instance Methods
Source
# File lib/cucumber/formatter/interceptor.rb, line 23 def buffer_string @lock.synchronize do return @buffer.string.dup end end
Source
# File lib/cucumber/formatter/interceptor.rb, line 34 def method_missing(method, *args, &blk) @pipe.respond_to?(method) ? @pipe.send(method, *args, &blk) : super end
Calls superclass method
Source
# File lib/cucumber/formatter/interceptor.rb, line 38 def respond_to_missing?(method, include_private = false) super || @pipe.respond_to?(method, include_private) end
Calls superclass method
Source
# File lib/cucumber/formatter/interceptor.rb, line 29 def unwrap! @wrapped = false @pipe end
Source
# File lib/cucumber/formatter/interceptor.rb, line 16 def write(str) @lock.synchronize do @buffer << str if @wrapped return @pipe.write(str) end end