Class: I18n::Processes::Scanners::Files::CachingFileFinder

Inherits:
FileFinder
  • Object
show all
Defined in:
lib/i18n/processes/scanners/files/caching_file_finder.rb

Overview

Note:

This class is thread-safe. All methods are cached.

Finds the files in the specified search paths with support for exclusion / inclusion patterns. Wraps a FileFinder and caches the results.

Since:

  • 0.9.0

Constant Summary

Constants included from Logging

Logging::MUTEX, Logging::PROGRAM_NAME

Instance Method Summary collapse

Methods included from Logging

log_error, log_stderr, log_verbose, log_warn, program_name, warn_deprecated

Constructor Details

#initialize(**args) ⇒ CachingFileFinder

Returns a new instance of CachingFileFinder.

Parameters:

  • paths (Array<String>)

    Find.find-compatible paths to traverse, absolute or relative to the working directory.

  • only (Array<String>, nil)

    File.fnmatch-compatible patterns files to include. Files not matching any of the inclusion patterns will be excluded.

  • exclude (Arry<String>)

    File.fnmatch-compatible patterns of files to exclude. Files matching any of the exclusion patterns will be excluded even if they match an inclusion pattern.

Since:

  • 0.9.0



12
13
14
15
16
# File 'lib/i18n/processes/scanners/files/caching_file_finder.rb', line 12

def initialize(**args)
  super
  @mutex = Mutex.new
  @cached_paths = nil
end

Instance Method Details

#find_filesArray<String>

Note:

This method is cached, it will only access the filesystem on the first invocation.

Returns found files.

Returns:

  • (Array<String>)

    found files

Since:

  • 0.9.0



30
31
32
# File 'lib/i18n/processes/scanners/files/caching_file_finder.rb', line 30

def find_files
  @cached_paths || @mutex.synchronize { @cached_paths ||= super }
end

#traverse_files {|path| ... } ⇒ Array<of block results>

Note:

This method is cached, it will only access the filesystem on the first invocation.

Traverse the paths and yield the matching ones.

Yield Parameters:

  • path (String)

    the path of the found file.

Returns:

  • (Array<of block results>)

Since:

  • 0.9.0



24
25
26
# File 'lib/i18n/processes/scanners/files/caching_file_finder.rb', line 24

def traverse_files
  super
end