Sha256: b498a38f3e599e43ac6f4489661db3163e73ab7d1083e60581c5ace09f294351
Contents?: true
Size: 847 Bytes
Versions: 8
Compression:
Stored size: 847 Bytes
Contents
# encoding: utf-8 # frozen_string_literal: true module RuboCop # Common methods and behaviors for dealing with paths. module PathUtil module_function def relative_path(path, base_dir = Dir.pwd) # Optimization for the common case where path begins with the base # dir. Just cut off the first part. return path[(base_dir.length + 1)..-1] if path.start_with?(base_dir) path_name = Pathname.new(File.expand_path(path)) path_name.relative_path_from(Pathname.new(base_dir)).to_s end def match_path?(pattern, path) case pattern when String File.fnmatch?(pattern, path, File::FNM_PATHNAME) when Regexp path =~ pattern end end # Returns true for an absolute Unix or Windows path. def absolute?(path) path =~ %r{\A([A-Z]:)?/} end end end
Version data entries
8 entries across 8 versions & 2 rubygems