Sha256: 8c2c6adcfcf513cdc8a517fdcbf26e32b30ea1267e8b226b81fa60ad041cf7df

Contents?: true

Size: 721 Bytes

Versions: 28

Compression:

Stored size: 721 Bytes

Contents

# frozen_string_literal: true

module Bootsnap
  module LoadPathCache
    class RealpathCache
      def initialize
        @cache = Hash.new { |h, k| h[k] = realpath(*k) }
      end

      def call(*key)
        @cache[key]
      end

      private

      def realpath(caller_location, path)
        base = File.dirname(caller_location)
        abspath = File.expand_path(path, base).freeze
        find_file(abspath)
      end

      def find_file(name)
        return File.realpath(name).freeze if File.exist?(name)
        CACHED_EXTENSIONS.each do |ext|
          filename = "#{name}#{ext}"
          return File.realpath(filename).freeze if File.exist?(filename)
        end
        name
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bootsnap-1.9.4 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.9.3 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.9.2 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.9.1 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.9.0 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.8.1 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.8.0 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.7 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.6 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.5 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.4 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.3 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.2 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.1 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.1.pre1 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.7.0 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.6.0 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.5.1-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.5.0-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.5.1 lib/bootsnap/load_path_cache/realpath_cache.rb