Sha256: 2cad216557523c9510e23258514e00c410eee30674d2646d1e6b5fa5fc4661ba

Contents?: true

Size: 945 Bytes

Versions: 1

Compression:

Stored size: 945 Bytes

Contents

module Yoda
  module Services
    class LoadablePathResolver
      def initialize
      end

      # @param base_paths [Array<String>]
      # @param pattern [String]
      # @return [String, nil]
      def find_loadable_path(base_paths, pattern)
        # TODO: Support absolute path
        return nil if File.absolute_path?(pattern)
        return nil if pattern.start_with?("~/")
        return nil if pattern.start_with?("./")
        return nil if pattern.start_with?("../")

        base_paths.each do |base_path|
          path = File.join(base_path, pattern)

          if File.extname(path).empty?
            paths_with_suffix = ::Gem.suffixes.map { |suffix| path + suffix }
            matched_path = paths_with_suffix.find { |path| File.file?(path) }
            return matched_path if matched_path
          else
            return path if File.file?(path)
          end
        end

        return nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yoda-language-server-0.10.0 lib/yoda/services/loadable_path_resolver.rb