class ActiveSupport::EventedFileUpdateChecker::PathHelper
def ascendant_of?(base, other)
def ascendant_of?(base, other) base != other && other.ascend do |ascendant| break true if base == ascendant end end
def existing_parent(dir)
def existing_parent(dir) dir.ascend do |ascendant| break ascendant if ascendant.directory? end end
def filter_out_descendants(dirs)
def filter_out_descendants(dirs) return dirs if dirs.length < 2 dirs_sorted_by_nparts = dirs.sort_by { |dir| dir.each_filename.to_a.length } descendants = [] until dirs_sorted_by_nparts.empty? dir = dirs_sorted_by_nparts.shift dirs_sorted_by_nparts.reject! do |possible_descendant| ascendant_of?(dir, possible_descendant) && descendants << possible_descendant end end # Array#- preserves order. dirs - descendants end
def longest_common_subpath(paths)
Given a collection of Pathname objects returns the longest subpath
def longest_common_subpath(paths) return if paths.empty? lcsp = Pathname.new(paths[0]) paths[1..-1].each do |path| until ascendant_of?(lcsp, path) if lcsp.root? # If we get here a root directory is not an ascendant of path. # This may happen if there are paths in different drives on # Windows. return else lcsp = lcsp.parent end end end lcsp end
def normalize_extension(ext)
def normalize_extension(ext) ext.to_s.sub(/\A\./, '') end
def xpath(path)
def xpath(path) Pathname.new(path).expand_path end