Class: I18n::Tasks::Scanners::Files::CachingFileFinderProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/tasks/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



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

def initialize(exclude: [])
  @cache = ::I18n::Tasks::Concurrent::Cache.new
  @defaults = { exclude: exclude }
end

Instance Method Details

#get(**file_finder_args) ⇒ CachingFileFinder

Initialize a I18n::Tasks::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
# File 'lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb', line 22

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