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 |
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'). - #segment_pattern private
Filter - Inherited
Constructor Details
This class inherits a constructor from SimpleCov::Filter
Instance Method Details
#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 59
def matches?(source_file) source_file.project_filename.match?(segment_pattern) end
#segment_pattern (private)
[ GitHub ]# File 'lib/simplecov/filter.rb', line 65
def segment_pattern @segment_pattern ||= begin normalized = filter_argument.delete_prefix("/") if normalized.include?(".") # Contains a dot — looks like a filename pattern. Allow substring # match within the last path segment (e.g. "test.rb" matches # "faked_test.rb") while still anchoring to a "/" boundary. %r{/[^/]*#{Regexp.escape(normalized)}} elsif normalized.end_with?("/") # Trailing slash signals directory-only matching %r{/#{Regexp.escape(normalized)}} else # No dot — looks like a directory or path. Require segment-boundary # match so "lib" matches "/lib/" but not "/library/". %r{/#{Regexp.escape(normalized)}(?=[/.]|$)} end end end