Class: I18n::Processes::Scanners::Files::CachingFileFinderProvider

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

Overview

Note:

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

Finds the files and provides their contents.

Since:

  • 0.9.0

Instance Method Summary collapse

Constructor Details

#initialize(exclude: []) ⇒ CachingFileFinderProvider

Returns a new instance of CachingFileFinderProvider.

Parameters:

  • exclude (Array<String>) (defaults to: [])

Since:

  • 0.9.0



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

def initialize(exclude: [])
  @cache = {}
  @mutex = Mutex.new
  @defaults = { exclude: exclude }
end

Instance Method Details

#get(**file_finder_args) ⇒ CachingFileFinder

Initialize a I18n::Processes::Scanners::Files::CachingFileFinder or get one from cache based on the constructor arguments.

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.

Returns:

Since:

  • 0.9.0



22
23
24
25
26
27
28
29
30
31
# File 'lib/i18n/processes/scanners/files/caching_file_finder_provider.rb', line 22

def get(**file_finder_args)
  @cache[file_finder_args] || @mutex.synchronize do
    @cache[file_finder_args] ||= begin
      args = file_finder_args.dup
      args[:exclude] = @defaults[:exclude] + (args[:exclude] || [])
      args[:exclude].uniq!
      CachingFileFinder.new(**args)
    end
  end
end