Sha256: daf5710f5345681bdc2d2105c867615f7949023cc19bdc936e1e3dcab58c6e16

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

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

4 entries across 4 versions & 1 rubygems

Version Path
i18n-tasks-0.9.2 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.1 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.0 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb
i18n-tasks-0.9.0.rc2 lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb