Class: SimpleCov::Filter

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

Overview

Base filter class. Inherit from this to create custom filters, and overwrite the passes?(source_file) instance method

# A sample class that rejects all source files. class StupidFilter < SimpleCov::Filter

def passes?(source_file)
  false
end

end

Direct Known Subclasses

ArrayFilter, BlockFilter, RegexFilter, StringFilter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter_argument) ⇒ Filter

Returns a new instance of Filter


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

def initialize(filter_argument)
  @filter_argument = filter_argument
end

Instance Attribute Details

#filter_argumentObject (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) ⇒ Object


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

def self.build_filter(filter_argument)
  return filter_argument if filter_argument.is_a?(SimpleCov::Filter)
  class_for_argument(filter_argument).new(filter_argument)
end

.class_for_argument(filter_argument) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/simplecov/filter.rb', line 35

def self.class_for_argument(filter_argument)
  if filter_argument.is_a?(String)
    SimpleCov::StringFilter
  elsif filter_argument.is_a?(Regexp)
    SimpleCov::RegexFilter
  elsif filter_argument.is_a?(Array)
    SimpleCov::ArrayFilter
  elsif filter_argument.is_a?(Proc)
    SimpleCov::BlockFilter
  else
    raise ArgumentError, "You have provided an unrecognized filter type"
  end
end

Instance Method Details

#matches?(_) ⇒ Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/simplecov/filter.rb', line 21

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

#passes?(source_file) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
28
# File 'lib/simplecov/filter.rb', line 25

def passes?(source_file)
  warn "#{Kernel.caller.first}: [DEPRECATION] #passes? is deprecated. Use #matches? instead."
  matches?(source_file)
end