Sha256: 2cf0be83efacf04910dba5347a698d52aa4210e9fbe49f44ddcfad1b876ac988

Contents?: true

Size: 979 Bytes

Versions: 12

Compression:

Stored size: 979 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

12 entries across 12 versions & 1 rubygems

Version Path
i18n-tasks-0.9.24 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.23 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.22 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.21 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.20 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.19 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.18 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.17 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.16 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.15 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.14 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.13 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb