Sha256: 72e42895c9bcc8add0f61a1e2e387c8686b34c41d2c533d5482ad3ae84ae7bd9

Contents?: true

Size: 1.24 KB

Versions: 17

Compression:

Stored size: 1.24 KB

Contents

module Mutant
  # Stream filter for warnings
  class WarningFilter
    include Equalizer.new(:target)

    WARNING_PATTERN = /\A(?:.+):(?:\d+): warning: (?:.+)\n\z/

    # Initialize object
    #
    # @param [#write] target
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(target)
      @target   = target
      @warnings = []
    end

    # Return filtered warnings
    #
    # @return [Array<String>]
    #
    # @api private
    #
    attr_reader :warnings

    # Return target
    #
    # @return [#write] target
    #
    # @return [undefined]
    #
    # @api private
    #
    attr_reader :target
    protected :target

    # Write message to target filtering warnings
    #
    # @param [String] message
    #
    # @return [self]
    #
    # @api private
    #
    def write(message)
      if WARNING_PATTERN =~ message
        warnings << message
      else
        target.write(message)
      end

      self
    end

    # Use warning filter during block execution
    #
    # @return [Array<String>]
    #
    # @api private
    #
    def self.use
      original = $stderr
      $stderr = filter = new(original)
      yield
      filter.warnings
    ensure
      $stderr = original
    end

  end # WarningFilter
end # Mutant

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
mutant-0.8.0 lib/mutant/warning_filter.rb
mutant-0.7.9 lib/mutant/warning_filter.rb
mutant-0.7.8 lib/mutant/warning_filter.rb
mutant-0.7.7 lib/mutant/warning_filter.rb
mutant-0.7.6 lib/mutant/warning_filter.rb
mutant-0.7.5 lib/mutant/warning_filter.rb
mutant-0.7.4 lib/mutant/warning_filter.rb
mutant-0.7.3 lib/mutant/warning_filter.rb
mutant-0.7.2 lib/mutant/warning_filter.rb
mutant-0.7.1 lib/mutant/warning_filter.rb
mutant-0.6.7 lib/mutant/warning_filter.rb
mutant-0.6.6 lib/mutant/warning_filter.rb
mutant-0.6.5 lib/mutant/warning_filter.rb
mutant-0.6.4 lib/mutant/warning_filter.rb
mutant-0.6.3 lib/mutant/warning_filter.rb
mutant-0.6.2 lib/mutant/warning_filter.rb
mutant-0.6.0 lib/mutant/warning_filter.rb