/usr/lib/ruby/vendor_ruby/yell/silencer.rb is in ruby-yell 2.0.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # encoding: utf-8
module Yell #:nodoc:
# The +Yell::Silencer+ is your handly helper for stiping out unwanted log messages.
class Silencer
class PresetNotFound < StandardError
def message; "Could not find a preset for #{super.inspect}"; end
end
Presets = {
:assets => [/\AStarted GET "\/assets/, /\AServed asset/, /\A\s*\z/] # for Rails
}
def initialize( *patterns )
@patterns = patterns.dup
end
# 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
def add( *patterns )
patterns.each { |pattern| add!(pattern) }
self
end
# Clears out all the messages that would match any defined pattern
#
# @example
# call(['username', 'password'])
# #=> ['username]
#
# @return [Array] The remaining messages
def call( *messages )
return messages if @patterns.empty?
messages.reject { |m| matches?(m) }
end
# Get a pretty string
def inspect
"#<#{self.class.name} patterns: #{@patterns.inspect}>"
end
# @private
def patterns
@patterns
end
private
def add!( pattern )
@patterns = @patterns | fetch(pattern)
end
def fetch( pattern )
case pattern
when Symbol then Presets[pattern] or raise PresetNotFound.new(pattern)
else [pattern]
end
end
# Check if the provided message matches any of the defined patterns.
#
# @example
# matches?('password')
# #=> true
#
# @return [Boolean] true or false
def matches?( message )
@patterns.any? { |pattern| message.respond_to?(:match) && message.match(pattern) }
end
end
end
|