Class: SimpleCov::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/filter.rb,
sig/simplecov.rbs

Overview

Base filter class. Inherit from this to create custom filters, and override matches?(source_file).

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)


11
12
13
# File 'lib/simplecov/filter.rb', line 11

def initialize(filter_argument)
  @filter_argument = filter_argument
end

Instance Attribute Details

#filter_argumentT (readonly)

Returns the value of attribute filter_argument.

Returns:

  • (T)


9
10
11
# File 'lib/simplecov/filter.rb', line 9

def filter_argument
  @filter_argument
end

Class Method Details

.build_filter(filter_argument, string_filter: StringFilter) ⇒ Filter[untyped]

string_filter selects the semantics of bare String arguments: StringFilter's segment-substring match for skip, GlobFilter for cover. It 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: StringFilter)

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/simplecov/filter.rb', line 31

def self.build_filter(filter_argument, string_filter: StringFilter)
  case filter_argument
  when Filter then filter_argument
  when String then string_filter.new(filter_argument)
  when Array
    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:



41
42
43
44
# File 'lib/simplecov/filter.rb', line 41

def self.class_for_argument(filter_argument)
  filter_classes_by_argument_type.find { |type, _| filter_argument.is_a?(type) }&.last ||
    raise(ConfigurationError, "You have provided an unrecognized filter type")
end

Instance Method Details

#matches?(_source_file) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/simplecov/filter.rb', line 15

def matches?(_source_file)
  raise NotImplementedError, "The base filter class is not intended for direct use"
end

#path_only?Boolean

Whether this filter's verdict depends only on the file's path, so it can be decided before that file has any coverage. Used when recording which tracked files a process did not load. Defaults to false so a custom filter is never guessed at (#1250).

Returns:

  • (Boolean)


23
24
25
# File 'lib/simplecov/filter.rb', line 23

def path_only?
  false
end