Class: SimpleCov::StringFilter
- Defined in:
- lib/simplecov/filter.rb,
sig/simplecov.rbs
Instance Attribute Summary
Attributes inherited from Filter
Instance Method Summary collapse
- #compute_segment_pattern ⇒ Regexp
-
#matches?(source_file) ⇒ Boolean
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".
- #path_only? ⇒ Boolean
- #segment_pattern ⇒ Regexp
Methods inherited from Filter
build_filter, class_for_argument, #initialize
Constructor Details
This class inherits a constructor from SimpleCov::Filter
Instance Method Details
#compute_segment_pattern ⇒ Regexp
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/simplecov/filter.rb', line 75 def compute_segment_pattern normalized = filter_argument.delete_prefix("/") escaped = Regexp.escape(normalized) boundary = '(?:\A|/)' if normalized.end_with?("/") # Trailing slash signals directory-only matching. /#{boundary}#{escaped}/ elsif normalized.include?(".") && !normalized.include?("/") # Bare filename pattern ("test.rb" matches "faked_test.rb"): allow a # substring match within a single path segment. Multi-segment arguments # must not get this relaxation, or "app/models/user.rb" would also # match "webapp/models/user.rb". No boundary here: `[^/]*` already # reaches back to the segment start, so prefixing one matches the same # paths. %r{[^/]*#{escaped}(?=[/.]|\z)} else # Require a segment-boundary match so "lib" matches "lib/" but not # "library/". %r{#{boundary}#{escaped}(?=[/.]|\z)} end end |
#matches?(source_file) ⇒ Boolean
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".
61 62 63 |
# File 'lib/simplecov/filter.rb', line 61 def matches?(source_file) source_file.project_filename.match?(segment_pattern) end |
#path_only? ⇒ Boolean
65 66 67 |
# File 'lib/simplecov/filter.rb', line 65 def path_only? true end |
#segment_pattern ⇒ Regexp
71 72 73 |
# File 'lib/simplecov/filter.rb', line 71 def segment_pattern @segment_pattern ||= compute_segment_pattern end |