Module: Todoloo::Helpers
Instance Method Summary collapse
-
#glob_paths(pattern, excludes: []) ⇒ Enumerator<String>
Returns an
Enumeratorover the paths that matchpattern.
Instance Method Details
#glob_paths(pattern, excludes: []) ⇒ Enumerator<String>
Returns an Enumerator over the paths that match pattern
TODO We need to optimize how we traverse the file-system so that we can short-circuit the excludes instead of only filtering after finding them.
TODO Optimize the seen_path handling
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/todoloo/helpers.rb', line 18 def glob_paths(pattern, excludes: []) seen_paths = Set.new Enumerator.new do |y| Dir[*Array(pattern)].lazy.each do |path| if !(seen_paths.include?(path) || excludes.any? { |e| File.fnmatch(e, path) }) y << path end seen_paths << path end end end |