class Yell::Silencer

The Yell::Silencer is your handly helper for stiping out unwanted log messages.

Constants

Presets

Public Class Methods

new( *patterns ) click to toggle source
# File lib/yell/silencer.rb, line 15
def initialize( *patterns )
  @patterns = patterns.dup
end

Public Instance Methods

add( *patterns ) click to toggle source

Add one or more patterns to the silencer

@example

add( 'password' )
add( 'username', 'password' )

@example Add regular expressions

add( /password/ )

@return [self] The silencer instance

# File lib/yell/silencer.rb, line 29
def add( *patterns )
  patterns.each { |pattern| add!(pattern) }

  self
end
call( *messages ) click to toggle source

Clears out all the messages that would match any defined pattern

@example

call(['username', 'password'])
#=> ['username]

@return [Array] The remaining messages

# File lib/yell/silencer.rb, line 42
def call( *messages )
  return messages if @patterns.empty?

  messages.reject { |m| matches?(m) }
end
inspect() click to toggle source

Get a pretty string

# File lib/yell/silencer.rb, line 49
def inspect
  "#<#{self.class.name} patterns: #{@patterns.inspect}>"
end
patterns() click to toggle source

@private

# File lib/yell/silencer.rb, line 54
def patterns
  @patterns
end

Private Instance Methods

add!( pattern ) click to toggle source
# File lib/yell/silencer.rb, line 61
def add!( pattern )
  @patterns = @patterns | fetch(pattern)
end
fetch( pattern ) click to toggle source
# File lib/yell/silencer.rb, line 65
def fetch( pattern )
  case pattern
  when Symbol then Presets[pattern] or raise PresetNotFound.new(pattern)
  else [pattern]
  end
end
matches?( message ) click to toggle source

Check if the provided message matches any of the defined patterns.

@example

matches?('password')
#=> true

@return [Boolean] true or false

# File lib/yell/silencer.rb, line 79
def matches?( message )
  @patterns.any? { |pattern| message.respond_to?(:match) && message.match(pattern) }
end