module Compath::PathSorter

TODO: Remove Pathname Sorted files and directories are ordered as below

1. directory
2. file

Public Instance Methods

sort(paths) click to toggle source
# File lib/compath/path_sorter.rb, line 9
def sort(paths)
  sorted_pathnames.map(&:to_path) & paths
end
sorted_pathnames(path = '.') click to toggle source
# File lib/compath/path_sorter.rb, line 13
def sorted_pathnames(path = '.')
  collected = []
  current = Pathname.new(path)
  if current.directory?
    collected << current
    collected += current.children.flat_map { |child| sorted_pathnames(child) }
  else
    collected << current
  end

  collected
end