Method: CodeLister.files
- Defined in:
- lib/code_lister/code_lister.rb
.files(args = {}) ⇒ Array<String>
List files base on multiple simple criteria
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/code_lister/code_lister.rb', line 49 def files(args = {}) opts = { base_dir: Dir.pwd, recursive: true, exts: [], non_exts: [] }.merge(args) # always expand the path base_dir = File.(opts[:base_dir]) fail CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exist?(base_dir) wildcard = opts[:recursive] ? "**" : "" exts = opts[:exts] non_exts = opts[:non_exts] files_with_extension = Dir.glob(File.join(base_dir, wildcard, "*.{#{exts.join(",")}}")) files_without_extension = no_extension_files(base_dir, wildcard, non_exts) # Replace prefix directory with just "." files = (files_with_extension + files_without_extension) files.map! { |file| file.gsub(base_dir, ".") }.sort end |