Class: SimpleCov::StringFilter
- Defined in:
- lib/simplecov/filter.rb,
sig/simplecov.rbs
Overview
Matches when the project path contains the configured string at a path-segment boundary ("lib" matches "lib/foo.rb" but not "library/").
Instance Attribute Summary
Attributes inherited from Filter
Instance Method Summary collapse
- #compute_segment_pattern ⇒ Regexp
-
#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').
-
#path_only? ⇒ Boolean
Whether the verdict depends only on the path, so it can be decided before the file has any coverage.
- #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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/simplecov/filter.rb', line 86 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 (e.g. "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". %r{#{boundary}[^/]*#{escaped}(?=[/.]|\z)} 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".
72 73 74 |
# File 'lib/simplecov/filter.rb', line 72 def matches?(source_file) source_file.project_filename.match?(segment_pattern) end |
#path_only? ⇒ Boolean
Whether the verdict depends only on the path, so it can be decided before the file has any coverage.
1248 1249 1250 |
# File 'sig/simplecov.rbs', line 1248 def path_only? true end |
#segment_pattern ⇒ Regexp
82 83 84 |
# File 'lib/simplecov/filter.rb', line 82 def segment_pattern @segment_pattern ||= compute_segment_pattern end |