Class: SimpleCov::Filter

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter_argument) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • filter_argument (T)


18
19
20
# File 'lib/simplecov/filter.rb', line 18

def initialize(filter_argument)
  @filter_argument = filter_argument
end

Instance Attribute Details

#filter_argumentT (readonly)

Returns the value of attribute filter_argument.

Returns:

  • (T)


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.

Parameters:

  • filter_argument (filter_arg)
  • string_filter: (singleton(Filter)) (defaults to: SimpleCov::StringFilter)

Returns:



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)

Parameters:

  • filter_argument (filter_arg)

Returns:



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.

Parameters:

Returns:

  • (boolish)


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.

Returns:

  • (Boolean)


30
31
32
# File 'lib/simplecov/filter.rb', line 30

def path_only?
  false
end