Module: Rubocop::PathUtil
- Included in:
- Config, Cop::Util, Formatter::DisabledLinesFormatter, Formatter::JSONFormatter, 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
13 14 15 16 17 18 19 20 21 |
# File 'lib/rubocop/path_util.rb', line 13 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 11 |
# File 'lib/rubocop/path_util.rb', line 8 def relative_path(path, base_dir = Dir.pwd) path_name = Pathname.new(File.(path)) path_name.relative_path_from(Pathname.new(base_dir)).to_s end |