Module: Rubocop::PathUtil

Included in:
Cop::Util, Formatter::SimpleTextFormatter
Defined in:
lib/rubocop/path_util.rb

Overview

Common methods and behaviors for dealing with paths.

Class Method Summary collapse

Class Method Details

.match_path?(pattern, path) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
# File 'lib/rubocop/path_util.rb', line 12

def match_path?(pattern, path)
  case pattern
  when String
    basename = File.basename(path)
    path == pattern || basename == pattern || File.fnmatch(pattern, path)
  when Regexp
    path =~ pattern
  end
end

.relative_path(path, base_dir = Dir.pwd) ⇒ Object



8
9
10
# File 'lib/rubocop/path_util.rb', line 8

def relative_path(path, base_dir = Dir.pwd)
  Pathname.new(path).relative_path_from(Pathname.new(base_dir)).to_s
end