123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::StringFilter

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Filter
Instance Chain:
self, Filter
Inherits: SimpleCov::Filter
Defined in: lib/simplecov/filter.rb

Overview

Filter that matches when the source file's project path contains the configured string at a path-segment boundary.

Class Method Summary

Instance Attribute Summary

Filter - Inherited

Instance Method Summary

Filter - Inherited

Constructor Details

This class inherits a constructor from SimpleCov::Filter

Instance Method Details

#compute_segment_pattern (private)

[ GitHub ]

  
# File 'lib/simplecov/filter.rb', line 66

def compute_segment_pattern
  normalized = filter_argument.delete_prefix("/")
  escaped    = Regexp.escape(normalized)
  boundary   = '(?:\A|/)'

  if normalized.include?(".")
    # Filename pattern (e.g. "test.rb" matches "faked_test.rb"): allow
    # substring match within the last path segment, anchored to a
    # segment boundary.
    %r{#{boundary}[^/]*#{escaped}}
  elsif normalized.end_with?("/")
    # Trailing slash signals directory-only matching.
    /#{boundary}#{escaped}/
  else
    # Directory or path: require a segment-boundary match so "lib"
    # matches "lib/" but not "library/".
    %r{#{boundary}#{escaped}(?=[/.]|\z)}
  end
end

#matches?(source_file) ⇒ Boolean

Returns true when the given source file's filename matches the string configured when initializing this Filter with StringFilter.new('somestring'). Matching is path-segment-aware: the argument must appear immediately after a "/" and be followed by "/" or end-of-string, so "lib" matches "/lib/foo.rb" but not "/app/models/library.rb".

[ GitHub ]

  
# File 'lib/simplecov/filter.rb', line 56

def matches?(source_file)
  source_file.project_filename.match?(segment_pattern)
end

#segment_pattern (private)

[ GitHub ]

  
# File 'lib/simplecov/filter.rb', line 62

def segment_pattern
  @segment_pattern ||= compute_segment_pattern
end