Module: Compath::PathSorter

Defined in:
lib/compath/path_sorter.rb

Overview

TODO: Remove Pathname

Class Method Summary collapse

Class Method Details

.sort(paths) ⇒ Object



6
7
8
# File 'lib/compath/path_sorter.rb', line 6

def sort(paths)
  sorted_pathnames.map(&:to_path) & paths
end

.sorted_pathnames(path = '.') ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/compath/path_sorter.rb', line 10

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