class SimpleCov::StringFilter
configured string at a path-segment boundary.
Filter that matches when the source file’s project path contains the
def compute_segment_pattern
def compute_segment_pattern normalized = filter_argument.delete_prefix("/") escaped = Regexp.escape(normalized) boundary = '(?:\A|/)' if normalized.include?(".") # Filename pattern (e.g. "test.rb" matches "faked_test.rb"): allow # substring match within the last path segment, anchored to a # segment boundary. %r{#{boundary}[^/]*#{escaped}} elsif normalized.end_with?("/") # Trailing slash signals directory-only matching. /#{boundary}#{escaped}/ else # Directory or path: require a segment-boundary match so "lib" # matches "lib/" but not "library/". %r{#{boundary}#{escaped}(?=[/.]|\z)} end end
def matches?(source_file)
and be followed by "/" or end-of-string, so "lib" matches "/lib/foo.rb" but not
Matching is path-segment-aware: the argument must appear immediately after a "/"
string configured when initializing this Filter with StringFilter.new('somestring').
Returns true when the given source file's filename matches the
def matches?(source_file) source_file.project_filename.match?(segment_pattern) end
def segment_pattern
def segment_pattern @segment_pattern ||= compute_segment_pattern end