Sha256: d0d94823646f7003971907cb5e60e1868d25e4498402d40b8cab3d70e0109834

Contents?: true

Size: 978 Bytes

Versions: 6

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true
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 = {}
      @mutex = Mutex.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[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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
i18n-tasks-0.9.12 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.11 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.10 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.9 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.8 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.7 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb