Class: Kuby::Docker::DockerURI

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/docker/docker_uri.rb

Constant Summary collapse

DEFAULT_REGISTRY_HOST =

extend T::Sig

'docker.io'.freeze
DEFAULT_REGISTRY_INDEX_HOST =
'index.docker.io'.freeze
DEFAULT_PORT =
443

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, path) ⇒ DockerURI

T::Sig::WithoutRuntime.sig { params(host: String, port: Integer, path: String).void }



63
64
65
66
67
# File 'lib/kuby/docker/docker_uri.rb', line 63

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

Instance Attribute Details

#hostObject (readonly)

T::Sig::WithoutRuntime.sig { returns(String) }



54
55
56
# File 'lib/kuby/docker/docker_uri.rb', line 54

def host
  @host
end

#pathObject (readonly)

T::Sig::WithoutRuntime.sig { returns(String) }



60
61
62
# File 'lib/kuby/docker/docker_uri.rb', line 60

def path
  @path
end

#portObject (readonly)

T::Sig::WithoutRuntime.sig { returns(Integer) }



57
58
59
# File 'lib/kuby/docker/docker_uri.rb', line 57

def port
  @port
end

Class Method Details

.parse(url, default_host:, default_port:) ⇒ Object

T::Sig::WithoutRuntime.sig

params(
  url: String,
  default_host: T.nilable(String),
  default_port: T.nilable(Integer)
).returns(DockerURI)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kuby/docker/docker_uri.rb', line 37

def self.parse(url, default_host:, default_port:)
  if idx = url.index('://')
    url = url[(idx + 3)..-1] || ''
  end

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

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

.parse_index_uri(url) ⇒ Object

T::Sig::WithoutRuntime.sig { params(url: String).returns(DockerURI) }



22
23
24
25
26
27
28
# File 'lib/kuby/docker/docker_uri.rb', line 22

def self.parse_index_uri(url)
  parse(
    url,
    default_host: DEFAULT_REGISTRY_INDEX_HOST,
    default_port: DEFAULT_PORT
  )
end

.parse_uri(url) ⇒ Object

T::Sig::WithoutRuntime.sig { params(url: String).returns(DockerURI) }



13
14
15
16
17
18
19
# File 'lib/kuby/docker/docker_uri.rb', line 13

def self.parse_uri(url)
  parse(
    url,
    default_host: DEFAULT_REGISTRY_HOST,
    default_port: DEFAULT_PORT
  )
end

Instance Method Details

#has_default_port?Boolean

T::Sig::WithoutRuntime.sig { returns(T::Boolean) }

Returns:

  • (Boolean)


70
71
72
# File 'lib/kuby/docker/docker_uri.rb', line 70

def has_default_port?
  port == DEFAULT_PORT
end