Sha256: 3553d390e88382f5dedacb62b74fe77bbb801637fbb92642f53748e5ad6aeb5c
Contents?: true
Size: 1.35 KB
Versions: 11
Compression:
Stored size: 1.35 KB
Contents
module Steep class Project class Pattern attr_reader :patterns attr_reader :ignores attr_reader :prefixes attr_reader :ignore_prefixes attr_reader :ext def initialize(patterns:, ignores: [], ext:) @patterns = patterns @ignores = ignores @ext = ext @prefixes = patterns.map do |pat| if pat == "." || pat == "./" "" else pat.delete_prefix("./").delete_suffix(File::Separator) << File::Separator end end @ignore_prefixes = ignores.map do |pat| if pat == "." || pat == "./" "" else pat.delete_prefix("./").delete_suffix(File::Separator) << File::Separator end end end def =~(path) unless path.is_a?(Pathname) path = Pathname(path.to_s) end match?(path) && !ignore?(path) end def match?(path) test_string(path, patterns, prefixes) end def ignore?(path) test_string(path, ignores, ignore_prefixes) end def test_string(path, patterns, prefixes) string = path.to_s patterns.any? {|pat| File.fnmatch(pat, string, File::FNM_PATHNAME) } || prefixes.any? {|prefix| File.fnmatch("#{prefix}**/*#{ext}", string, File::FNM_PATHNAME) } end end end end
Version data entries
11 entries across 11 versions & 1 rubygems