Class: Kuby::Docker::DockerURI

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/kuby/docker/docker_uri.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, path) ⇒ DockerURI

Returns a new instance of DockerURI.



38
39
40
41
42
# File 'lib/kuby/docker/docker_uri.rb', line 38

def initialize(host, port, path)
  @host = host
  @port = port
  @path = path
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



29
30
31
# File 'lib/kuby/docker/docker_uri.rb', line 29

def host
  @host
end

#pathObject (readonly)

Returns the value of attribute path.



35
36
37
# File 'lib/kuby/docker/docker_uri.rb', line 35

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



32
33
34
# File 'lib/kuby/docker/docker_uri.rb', line 32

def port
  @port
end

Class Method Details

.parse(url) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kuby/docker/docker_uri.rb', line 12

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