Module: WhyClasses::FileFinder
- Defined in:
- lib/why_classes/file_finder.rb
Overview
Expands CLI paths into a concrete list of Ruby files, honouring the configuration's Include/Exclude globs. Explicitly-named files are always included; Exclude only filters directory expansion.
Class Method Summary collapse
- .excluded?(file, configuration) ⇒ Boolean
- .expand_dir(dir, configuration) ⇒ Object
- .find(paths, configuration) ⇒ Object
- .normalize(path) ⇒ Object
Class Method Details
.excluded?(file, configuration) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/why_classes/file_finder.rb', line 32 def excluded?(file, configuration) configuration.exclude_globs.any? do |glob| File.fnmatch?(glob, file, File::FNM_PATHNAME | File::FNM_EXTGLOB) || File.fnmatch?("**/#{glob}", file, File::FNM_PATHNAME | File::FNM_EXTGLOB) end end |
.expand_dir(dir, configuration) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/why_classes/file_finder.rb', line 23 def (dir, configuration) configuration.include_globs .flat_map { |glob| Dir.glob(File.join(dir, glob), File::FNM_EXTGLOB) } .select { |f| File.file?(f) } .map { |f| normalize(f) } .reject { |f| excluded?(f, configuration) } .uniq end |
.find(paths, configuration) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/why_classes/file_finder.rb', line 10 def find(paths, configuration) paths = ["."] if paths.nil? || paths.empty? files = [] paths.each do |path| if File.file?(path) files << normalize(path) elsif File.directory?(path) files.concat((path, configuration)) end end files.uniq end |
.normalize(path) ⇒ Object
39 40 41 |
# File 'lib/why_classes/file_finder.rb', line 39 def normalize(path) path.delete_prefix("./") end |