Sha256: 78cd996a0328209f2222ca190a71c2b70af6068e3172a25903b58fde89362fb3

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

# encoding: UTF-8

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]
    #
    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

13 entries across 13 versions & 1 rubygems

Version Path
mutant-0.5.23 lib/mutant/warning_filter.rb
mutant-0.5.22 lib/mutant/warning_filter.rb
mutant-0.5.21 lib/mutant/warning_filter.rb
mutant-0.5.20 lib/mutant/warning_filter.rb
mutant-0.5.19 lib/mutant/warning_filter.rb
mutant-0.5.18 lib/mutant/warning_filter.rb
mutant-0.5.17 lib/mutant/warning_filter.rb
mutant-0.5.16 lib/mutant/warning_filter.rb
mutant-0.5.15 lib/mutant/warning_filter.rb
mutant-0.5.14 lib/mutant/warning_filter.rb
mutant-0.5.13 lib/mutant/warning_filter.rb
mutant-0.5.12 lib/mutant/warning_filter.rb
mutant-0.5.11 lib/mutant/warning_filter.rb