Method: File.cleanpath
- Defined in:
- lib/yard/core_ext/file.rb
permalink .cleanpath(path, rel_root = false) ⇒ String
Cleans a path by removing extraneous ‘..’, ‘.’ and ‘/’ characters
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/yard/core_ext/file.rb', line 37 def self.cleanpath(path, rel_root = false) path = path.split(SEPARATOR) path = path.inject([]) do |acc, comp| next acc if comp == RELATIVE_SAMEDIR if comp == RELATIVE_PARENTDIR && !acc.empty? && acc.last != RELATIVE_PARENTDIR acc.pop next acc elsif !rel_root && comp == RELATIVE_PARENTDIR && acc.empty? next acc end acc << comp end File.join(*path) end |