Sha256: dee5e30f9f90bd5ed166933ad2e31995df4c60bb966cb9b57e2756f57a141b98

Contents?: true

Size: 1.66 KB

Versions: 12

Compression:

Stored size: 1.66 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 "DEPRECATION: SimpleCov::Filter#passes?(x) has been renamed to #matches?. Please update your custom filters accordingly!"
      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

12 entries across 12 versions & 5 rubygems

Version Path
suzuko-0.1.8 vendor/bundle/ruby/2.0.0/gems/simplecov-0.10.0/lib/simplecov/filter.rb
suzuko-0.1.7 vendor/bundle/ruby/2.0.0/gems/simplecov-0.10.0/lib/simplecov/filter.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/filter.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/filter.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/filter.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/simplecov-0.10.0/lib/simplecov/filter.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/simplecov-0.10.0/lib/simplecov/filter.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/simplecov-0.10.0/lib/simplecov/filter.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/simplecov-0.10.0/lib/simplecov/filter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/simplecov-0.10.0/lib/simplecov/filter.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/simplecov-0.10.0/lib/simplecov/filter.rb
simplecov-0.10.0 lib/simplecov/filter.rb