Class: SimpleCov::StringFilter
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Filter
|
|
|
Instance Chain:
self,
Filter
|
|
| Inherits: |
SimpleCov::Filter
|
| Defined in: | lib/simplecov/filter.rb |
Overview
Filter that matches when the source file's project path contains the
configured string at a path-segment boundary.
Class Method Summary
Filter - Inherited
Instance Attribute Summary
Filter - Inherited
Instance Method Summary
-
#matches?(source_file) ⇒ Boolean
Returns true when the given source file's filename matches the string configured when initializing this
FilterwithStringFilter.new('somestring'). - #compute_segment_pattern private
- #segment_pattern private
Filter - Inherited
Constructor Details
This class inherits a constructor from SimpleCov::Filter
Instance Method Details
#compute_segment_pattern (private)
[ GitHub ]# File 'lib/simplecov/filter.rb', line 66
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
#matches?(source_file) ⇒ Boolean
Returns true when the given source file's filename matches the
string configured when initializing this Filter with StringFilter.new('somestring').
Matching is path-segment-aware: the argument must appear immediately after a "/"
and be followed by "/" or end-of-string, so "lib" matches "/lib/foo.rb" but not
"/app/models/library.rb".
# File 'lib/simplecov/filter.rb', line 56
def matches?(source_file) source_file.project_filename.match?(segment_pattern) end
#segment_pattern (private)
[ GitHub ]# File 'lib/simplecov/filter.rb', line 62
def segment_pattern @segment_pattern ||= compute_segment_pattern end