Class: SimpleCov::Filter
- Inherits:
-
Object
- Object
- SimpleCov::Filter
- Defined in:
- lib/simplecov/filter.rb,
sig/simplecov.rbs
Overview
Base filter class. Inherit and override matches? to create custom
filters. T is the type of the configured filter argument.
Direct Known Subclasses
ArrayFilter, BlockFilter, GlobFilter, RegexFilter, StringFilter
Instance Attribute Summary collapse
-
#filter_argument ⇒ T
readonly
Returns the value of attribute filter_argument.
Class Method Summary collapse
-
.build_filter(filter_argument, string_filter: SimpleCov::StringFilter) ⇒ Filter[untyped]
string_filterselects the semantics of bare String arguments — StringFilter's segment-substring match foradd_filter/skip, GlobFilter forcover— and threads through Array elements so a list gets the same treatment as its members. - .class_for_argument(filter_argument) ⇒ singleton(Filter)
Instance Method Summary collapse
-
#initialize(filter_argument) ⇒ Filter
constructor
A new instance of Filter.
-
#matches?(_source_file) ⇒ boolish
The base implementation raises NotImplementedError.
-
#path_only? ⇒ Boolean
Whether the verdict depends only on the path, so it can be decided before the file has any coverage.
Constructor Details
#initialize(filter_argument) ⇒ Filter
Returns a new instance of Filter.
18 19 20 |
# File 'lib/simplecov/filter.rb', line 18 def initialize(filter_argument) @filter_argument = filter_argument end |
Instance Attribute Details
#filter_argument ⇒ T (readonly)
Returns the value of attribute filter_argument.
16 17 18 |
# File 'lib/simplecov/filter.rb', line 16 def filter_argument @filter_argument end |
Class Method Details
.build_filter(filter_argument, string_filter: SimpleCov::StringFilter) ⇒ Filter[untyped]
string_filter selects the semantics of bare String arguments —
StringFilter's segment-substring match for add_filter/skip,
GlobFilter for cover — and threads through Array elements so a
list gets the same treatment as its members.
38 39 40 41 42 43 44 45 46 |
# File 'lib/simplecov/filter.rb', line 38 def self.build_filter(filter_argument, string_filter: SimpleCov::StringFilter) case filter_argument when SimpleCov::Filter then filter_argument when String then string_filter.new(filter_argument) when Array SimpleCov::ArrayFilter.new(filter_argument.map { |arg| build_filter(arg, string_filter: string_filter) }) else class_for_argument(filter_argument).new(filter_argument) end end |
.class_for_argument(filter_argument) ⇒ singleton(Filter)
48 49 50 51 |
# File 'lib/simplecov/filter.rb', line 48 def self.class_for_argument(filter_argument) filter_classes_by_argument_type.find { |type, _| filter_argument.is_a?(type) }&.last || raise(SimpleCov::ConfigurationError, "You have provided an unrecognized filter type") end |
Instance Method Details
#matches?(_source_file) ⇒ boolish
The base implementation raises NotImplementedError.
1224 1225 1226 |
# File 'sig/simplecov.rbs', line 1224 def matches?(_source_file) raise NotImplementedError, "The base filter class is not intended for direct use" end |
#path_only? ⇒ Boolean
Whether the verdict depends only on the path, so it can be decided before the file has any coverage.
30 31 32 |
# File 'lib/simplecov/filter.rb', line 30 def path_only? false end |