Sha256: 1c1068c6c0719e89c717b58be9ca95595e05f43012da0bae55ed3b6153c8e9d4

Contents?: true

Size: 829 Bytes

Versions: 15

Compression:

Stored size: 829 Bytes

Contents

# 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

15 entries across 15 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/path_util.rb
rubocop-0.48.1 lib/rubocop/path_util.rb
rubocop-0.48.0 lib/rubocop/path_util.rb
rubocop-0.47.1 lib/rubocop/path_util.rb
rubocop-0.47.0 lib/rubocop/path_util.rb
rubocop-0.46.0 lib/rubocop/path_util.rb
rubocop-0.45.0 lib/rubocop/path_util.rb
rubocop-0.44.1 lib/rubocop/path_util.rb
rubocop-0.44.0 lib/rubocop/path_util.rb