Class: I18n::Tasks::Scanners::Files::FileFinder
- Inherits:
-
Object
- Object
- I18n::Tasks::Scanners::Files::FileFinder
- Includes:
- Logging
- Defined in:
- lib/i18n/tasks/scanners/files/file_finder.rb
Overview
Finds the files in the specified search paths with support for exclusion / inclusion patterns.
Direct Known Subclasses
Constant Summary
Constants included from Logging
Logging::MUTEX, Logging::PROGRAM_NAME
Instance Method Summary collapse
-
#find_files ⇒ Array<String>
Found files.
-
#initialize(paths: ['.'], only: nil, exclude: []) ⇒ FileFinder
constructor
A new instance of FileFinder.
-
#traverse_files {|path| ... } ⇒ Array<of block results>
Traverse the paths and yield the matching ones.
Methods included from Logging
log_error, log_stderr, log_verbose, log_warn, program_name, warn_deprecated
Constructor Details
#initialize(paths: ['.'], only: nil, exclude: []) ⇒ FileFinder
Returns a new instance of FileFinder.
16 17 18 19 20 21 22 |
# File 'lib/i18n/tasks/scanners/files/file_finder.rb', line 16 def initialize(paths: ['.'], only: nil, exclude: []) fail 'paths argument is required' if paths.nil? @paths = paths @include = only @exclude = exclude || [] end |
Instance Method Details
#find_files ⇒ Array<String>
Returns found files.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/i18n/tasks/scanners/files/file_finder.rb', line 34 def find_files # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity results = [] paths = @paths.select { |p| File.exist?(p) } log_warn "None of the search.paths exist #{@paths.inspect}" if paths.empty? Find.find(*paths) do |path| is_dir = File.directory?(path) hidden = File.basename(path).start_with?('.') && !%w[. ./].include?(path) not_incl = @include && !path_fnmatch_any?(path, @include) excl = path_fnmatch_any?(path, @exclude) if is_dir || hidden || not_incl || excl Find.prune if is_dir && (hidden || excl) else results << path end end results end |
#traverse_files {|path| ... } ⇒ Array<of block results>
Traverse the paths and yield the matching ones.
29 30 31 |
# File 'lib/i18n/tasks/scanners/files/file_finder.rb', line 29 def traverse_files(&block) find_files.map(&block) end |