Module: Copland::Implementation::IncludeExcludeFactory

Included in:
LoggingInterceptorFactory
Defined in:
lib/copland/impl/include-exclude.rb

Overview

A module encapsulating the factory end of a service with include/exclude functionality. Such functionality involves a schema with include and exclude elements, each of which must be an array of method names that should be included or excluded. See the IncludeExclude module for more info.

Constant Summary collapse

PATTERN =

This is the regular expression for parsing elements in an include or exclude array.

/^
(.*?)        (?# this matches the method name pattern)
(?:          (?# begin optional arity section)
  \(         (?# begin parenthesized section)
    ([<=>])? (?# optional comparator character)
    (\d+)    (?# arity specification)
  \)         (?# end parenthesized section)
)?           (?# end optional arity section)
$/x

Instance Method Summary collapse

Instance Method Details

#build_map(array) ⇒ Object

This is a utility function for converting an array of strings representing method name patterns, into an array of IncludeExcludePattern instances.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/copland/impl/include-exclude.rb', line 64

def build_map( array )
  ( array || [] ).map do |pattern|
    unless pattern =~ PATTERN
      raise CoplandException,
        "invalid logging interceptor method pattern: #{pattern.inspect}"
    end

    name = $1
    comparitor = $2
    arity = ( $3 || -1 ).to_i

    comparitor ||= ">" if arity < 0
    comparitor ||= "="
      
    IncludeExcludePattern.new( Regexp.new( "^" + name + "$" ),
                               comparitor,
                               arity )
  end
end