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.0"

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.



27
28
29
# File 'lib/warnings/warnings.rb', line 27

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.



40
41
42
43
44
45
46
47
48
49
# File 'lib/warnings/warnings.rb', line 40

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.



14
15
16
# File 'lib/warnings/warnings.rb', line 14

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