Module: Warnings

Defined in:
lib/warnings/mixin.rb,
lib/warnings/version.rb,
lib/warnings/warning.rb,
lib/warnings/warnings.rb

Defined Under Namespace

Modules: Mixin Classes: Warning

Constant Summary collapse

VERSION =

warnings version

"0.1.1"

Class Method Summary collapse

Class Method Details

.from(path) ⇒ Warning

Selects all warnings originating from a file.

Parameters:

  • path (String)

    The sub-path to search for.

Returns:

  • (Warning)

    The warnings from the sub-path.



45
46
47
# File 'lib/warnings/warnings.rb', line 45

def self.from(path)
  $WARNINGS.select { |warning| warning.source_file.include?(path) }
end

.from_method(name) ⇒ Warning

Selects all warnings originating from a method.

Parameters:

  • name (Regexp, String)

    The method name or pattern to search for.

Returns:

  • (Warning)

    The warnings from the specified method.



58
59
60
61
62
63
64
65
66
67
# File 'lib/warnings/warnings.rb', line 58

def self.from_method(name)
  selector = case name
            when Regexp
              lambda { |warning| warning.source_method =~ name }
            else
              lambda { |warning| warning.source_method == name }
            end

  $WARNINGS.select(&selector)
end

.grep(pattern) ⇒ Warning

Selects all warnings with a similar message.

Parameters:

  • pattern (String, Regexp)

    The message pattern to search for.

Returns:

  • (Warning)

    The warnings from the sub-path.



32
33
34
# File 'lib/warnings/warnings.rb', line 32

def self.grep(pattern)
  $WARNINGS.select { |warning| warning.message.match(pattern) }
end