Sha256: ce9379c8520d537ee5edf06bcaf6dbc2375ce1889ae37d823396b434b88f4b56

Contents?: true

Size: 1.62 KB

Versions: 13

Compression:

Stored size: 1.62 KB

Contents

module SimpleCov
  #
  # 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
  #
  class Filter
    attr_reader :filter_argument
    def initialize(filter_argument)
      @filter_argument = filter_argument
    end

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

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

  class StringFilter < SimpleCov::Filter
    # Returns true when the given source file's filename matches the
    # string configured when initializing this Filter with StringFilter.new('somestring)
    def matches?(source_file)
      (source_file.filename =~ /#{filter_argument}/)
    end
  end

  class BlockFilter < SimpleCov::Filter
    # Returns true if the block given when initializing this filter with BlockFilter.new {|src_file| ... }
    # returns true for the given source file.
    def matches?(source_file)
      filter_argument.call(source_file)
    end
  end

  class ArrayFilter < SimpleCov::Filter
    # Returns true if any of the file paths passed in the given array matches the string
    # configured when initializing this Filter with StringFilter.new(['some/path', 'other/path'])
    def matches?(source_files_list)
      filter_argument.any? do |arg|
        source_files_list.filename =~ /#{arg}/
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
cvss-suite-1.0.8 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.7 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.6 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.5 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.4 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.3 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.2 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.1 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
cvss-suite-1.0.0 vendor/cache/ruby/2.2.0/gems/simplecov-0.11.2/lib/simplecov/filter.rb
simplecov-0.11.2 lib/simplecov/filter.rb
simplecov-0.11.1 lib/simplecov/filter.rb
simplecov-0.11.0 lib/simplecov/filter.rb