class Bootsnap::LoadPathCache::RealpathCache

Public Class Methods

new() click to toggle source
# File lib/bootsnap/load_path_cache/realpath_cache.rb, line 5
def initialize
  @cache = Hash.new { |h, k| h[k] = realpath(*k) }
end

Public Instance Methods

call(*key) click to toggle source
# File lib/bootsnap/load_path_cache/realpath_cache.rb, line 9
def call(*key)
  @cache[key]
end

Private Instance Methods

find_file(name) click to toggle source
# File lib/bootsnap/load_path_cache/realpath_cache.rb, line 21
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
realpath(caller_location, path) click to toggle source
# File lib/bootsnap/load_path_cache/realpath_cache.rb, line 15
def realpath(caller_location, path)
  base = File.dirname(caller_location)
  abspath = File.expand_path(path, base).freeze
  find_file(abspath)
end