Sha256: 9412e6cba426f171933ccfcfc8785d316f1363b390b5f7b3c5105543a3d61f7f

Contents?: true

Size: 947 Bytes

Versions: 29

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

require 'i18n/tasks/concurrent/cache'
require 'i18n/tasks/scanners/files/caching_file_finder'

module I18n::Tasks::Scanners::Files
  # Finds the files and provides their contents.
  #
  # @note This class is thread-safe. All methods are cached.
  # @since 0.9.0
  class CachingFileFinderProvider
    # @param exclude [Array<String>]
    def initialize(exclude: [])
      @cache = ::I18n::Tasks::Concurrent::Cache.new
      @defaults = { exclude: exclude }
    end

    # Initialize a {CachingFileFinder} or get one from cache based on the constructor arguments.
    #
    # @param (see FileFinder#initialize)
    # @return [CachingFileFinder]
    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
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
i18n-tasks-0.9.33 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.32 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.31 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.30 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.29 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.28 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.27 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.26 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.25 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb