Sha256: 8172af44c4fedc8d16c27f92efae0761b8107d6bdaf3f6601e066d8b3403c5ab

Contents?: true

Size: 709 Bytes

Versions: 34

Compression:

Stored size: 709 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)
        file = find_file(File.expand_path(path, base))
        dir = File.dirname(file)
        File.join(dir, File.basename(file))
      end

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

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
bootsnap-1.4.6-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.6 lib/bootsnap/load_path_cache/realpath_cache.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/realpath_cache.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.5-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.5 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.4-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.4 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.3-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.3 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2.rc3 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2.rc2-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2.rc2 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2.rc1-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.2.rc1 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.1-java lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.1 lib/bootsnap/load_path_cache/realpath_cache.rb
bootsnap-1.4.0 lib/bootsnap/load_path_cache/realpath_cache.rb