Module: Compath::PathSorter

Defined in:
lib/compath/path_sorter.rb

Overview

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

1. directory
2. file

Class Method Summary collapse

Class Method Details

.sort(paths) ⇒ Object



9
10
11
# File 'lib/compath/path_sorter.rb', line 9

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

.sorted_pathnames(path = '.') ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# 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