class Cucumber::Formatter::Interceptor::Pipe

Attributes

pipe[R]

Public Class Methods

new(pipe) click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 8
def initialize(pipe)
  @pipe = pipe
  @buffer = StringIO.new
  @wrapped = true
end
unwrap!(pipe) click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 59
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
validate_pipe(pipe) click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 53
def self.validate_pipe(pipe)
  unless [:stdout, :stderr].include? pipe
    raise ArgumentError, '#wrap only accepts :stderr or :stdout'
  end
end
wrap(pipe) click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 73
def self.wrap(pipe)
  validate_pipe pipe

  case pipe
  when :stderr
    $stderr = self.new($stderr)
    return $stderr
  when :stdout
    $stdout = self.new($stdout)
    return $stdout
  end
end

Public Instance Methods

buffer() click to toggle source

@deprecated use buffer_string

# File lib/cucumber/formatter/interceptor.rb, line 22
def buffer
  require 'cucumber/deprecate.rb'
  Cucumber.deprecate(
    'Use Cucumber::Formatter::Interceptor::Pipe#buffer_string instead',
    'Cucumber::Formatter::Interceptor::Pipe#buffer',
    '3.99'
  )
  lock.synchronize do
    return @buffer.string.lines
  end
end
buffer_string() click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 34
def buffer_string
  lock.synchronize do
    return @buffer.string.dup
  end
end
method_missing(method, *args, &blk) click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 45
def method_missing(method, *args, &blk)
  @pipe.send(method, *args, &blk)
end
respond_to?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/cucumber/formatter/interceptor.rb, line 49
def respond_to?(method, include_private = false)
  super || @pipe.respond_to?(method, include_private)
end
unwrap!() click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 40
def unwrap!
  @wrapped = false
  @pipe
end
write(str) click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 14
def write(str)
  lock.synchronize do
    @buffer << str if @wrapped
    return @pipe.write(str)
  end
end

Private Instance Methods

lock() click to toggle source
# File lib/cucumber/formatter/interceptor.rb, line 88
def lock
  @lock ||= Mutex.new
end