A module encapsulating the functionality of a service with include/exclude functionality. Such functionality involves a the ability to specify a pair of include and exclude arrays, each of which must be an array of method names that should be included or excluded from some kind of processing.
This is the regular expression for parsing elements in an include or exclude array.
This is a utility function for converting an array of strings representing method name patterns, into an array of IncludeExcludePattern instances.
# File lib/needle/include-exclude.rb, line 46 46: def build_map( array ) 47: ( array || [] ).map do |pattern| 48: unless pattern =~ PATTERN 49: raise InterceptorConfigurationError, 50: "invalid logging interceptor method pattern: #{pattern.inspect}" 51: end 52: 53: name = $1 54: comparitor = $2 55: arity = ( $3 || 1 ).to_i 56: 57: comparitor ||= ">" if arity < 0 58: comparitor ||= "=" 59: 60: IncludeExcludePattern.new( Regexp.new( "^" + name + "$" ), 61: comparitor, 62: arity ) 63: end 64: end
Returns false if the given context object “matches” any of the exclude patterns without matching any of the include patterns. The context object must respond to the :sym and :args messages, where :sym is a symbol identifying the method being matched, and :args is an array of arguments that will be sent to that method.
# File lib/needle/include-exclude.rb, line 73 73: def match( context ) 74: match = true 75: 76: @excludes.each do |pattern| 77: if match_pattern( context, pattern ) 78: match = false 79: break 80: end 81: end 82: 83: unless match 84: @includes.each do |pattern| 85: if match_pattern( context, pattern ) 86: match = true 87: break 88: end 89: end 90: end 91: 92: return match 93: end
Returns true if the given context matches the given pattern, and false otherwise.
# File lib/needle/include-exclude.rb, line 98 98: def match_pattern( context, pattern ) 99: if context.sym.to_s =~ pattern.name 100: case pattern.comparitor 101: when "<" 102: return context.args.length < pattern.arity 103: when ">" 104: return context.args.length > pattern.arity 105: when "=" 106: return context.args.length == pattern.arity 107: end 108: end 109: 110: return false 111: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.