Class: Mutant::WarningFilter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/warning_filter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Stream filter for warnings

Constant Summary collapse

WARNING_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object



15
16
17
18
# File 'lib/mutant/warning_filter.rb', line 15

def initialize(target)
  @target   = target
  @warnings = []
end

Instance Attribute Details

#warningsArray<String> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Warnings captured by filter



23
24
25
# File 'lib/mutant/warning_filter.rb', line 23

def warnings
  @warnings
end

Class Method Details

.useArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Use warning filter during block execution



51
52
53
54
55
56
57
58
# File 'lib/mutant/warning_filter.rb', line 51

def self.use
  original = $stderr
  $stderr = filter = new(original)
  yield
  filter.warnings
ensure
  $stderr = original
end

Instance Method Details

#write(message) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Write message to target filtering warnings



38
39
40
41
42
43
44
45
46
# File 'lib/mutant/warning_filter.rb', line 38

def write(message)
  if WARNING_PATTERN =~ message
    warnings << message
  else
    target.write(message)
  end

  self
end