Sha256: b2be88740fa7b6fd3bd76902c0bfb41cbcc0054596fb77b7156b4c5de14c4d35

Contents?: true

Size: 1.72 KB

Versions: 27

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

module Cucumber
  module Formatter
    module Interceptor
      class Pipe
        attr_reader :pipe

        def initialize(pipe)
          @pipe = pipe
          @buffer = StringIO.new
          @wrapped = true
          @lock = Mutex.new
        end

        def write(str)
          @lock.synchronize do
            @buffer << str if @wrapped
            return @pipe.write(str)
          end
        end

        def buffer_string
          @lock.synchronize do
            return @buffer.string.dup
          end
        end

        def unwrap!
          @wrapped = false
          @pipe
        end

        def method_missing(method, *args, &blk)
          @pipe.respond_to?(method) ? @pipe.send(method, *args, &blk) : super
        end

        def respond_to_missing?(method, include_private = false)
          super || @pipe.respond_to?(method, include_private)
        end

        def self.validate_pipe(pipe)
          raise ArgumentError, '#wrap only accepts :stderr or :stdout' unless %i[stdout stderr].include? pipe
        end

        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

        def self.wrap(pipe)
          validate_pipe pipe

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

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
cucumber-9.2.1 lib/cucumber/formatter/interceptor.rb
cucumber-9.2.0 lib/cucumber/formatter/interceptor.rb
cucumber-9.1.2 lib/cucumber/formatter/interceptor.rb
cucumber-9.1.1 lib/cucumber/formatter/interceptor.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/formatter/interceptor.rb
cucumber-9.1.0 lib/cucumber/formatter/interceptor.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/formatter/interceptor.rb
cucumber-9.0.2 lib/cucumber/formatter/interceptor.rb
cucumber-9.0.1 lib/cucumber/formatter/interceptor.rb
cucumber-9.0.0 lib/cucumber/formatter/interceptor.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/interceptor.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/interceptor.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/interceptor.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/interceptor.rb
cucumber-8.0.0 lib/cucumber/formatter/interceptor.rb
cucumber-8.0.0.rc.1 lib/cucumber/formatter/interceptor.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-7.1.0/lib/cucumber/formatter/interceptor.rb
cucumber-7.1.0 lib/cucumber/formatter/interceptor.rb
cucumber-7.0.0 lib/cucumber/formatter/interceptor.rb
cucumber-6.1.0 lib/cucumber/formatter/interceptor.rb