Sha256: 586bfc01970ffabfd3de0772bc194f2c140c4f1c633c11c9f937488214e949e1

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# typed: strict

module Kuby
  module Docker
    class DockerURI
      extend T::Sig

      DEFAULT_REGISTRY_HOST = T.let('index.docker.io'.freeze, String)
      DEFAULT_REGISTRY_PORT = T.let(443, Integer)

      sig { params(url: String).returns(DockerURI) }
      def self.parse(url)
        if idx = url.index('://')
          url = url[(idx + 3)..-1] || ''
        end

        host_port, *path = url.split('/')
        host, port, *path = if host_port =~ /[.:]/
          hst, prt = T.must(host_port).split(':')
          [T.must(hst), prt || DEFAULT_REGISTRY_PORT, *path]
        else
          [DEFAULT_REGISTRY_HOST, DEFAULT_REGISTRY_PORT, host_port, *path]
        end

        new(host.to_s, port.to_i, (path || []).join('/'))
      end

      sig { returns(String) }
      attr_reader :host

      sig { returns(Integer) }
      attr_reader :port

      sig { returns(String) }
      attr_reader :path

      sig { params(host: String, port: Integer, path: String).void }
      def initialize(host, port, path)
        @host = host
        @port = port
        @path = path
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kuby-core-0.14.0 lib/kuby/docker/docker_uri.rb
kuby-core-0.13.0 lib/kuby/docker/docker_uri.rb
kuby-core-0.12.0 lib/kuby/docker/docker_uri.rb