Class: Tagfish::DockerURI
- Inherits:
-
Object
- Object
- Tagfish::DockerURI
- Defined in:
- lib/tagfish/docker_uri.rb
Constant Summary collapse
- URI_PARSER =
%r{ (https?:\/\/)? # Optional protocol (?:([\w.\-]+\.[\w.\-]+)\/)? # Optional registry ([\w\-]*\/?[\w\-.]+) # Optional namespace, mandatory repository :? # Optional delimiter between repository and tag ([\w.\-]+)? # Optional tag }x
Instance Attribute Summary collapse
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#registry ⇒ Object
Returns the value of attribute registry.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#tag ⇒ Object
Returns the value of attribute tag.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(protocol, registry, repository, tag) ⇒ DockerURI
constructor
A new instance of DockerURI.
- #repo_and_tag ⇒ Object
- #tag? ⇒ Boolean
- #tagged_latest? ⇒ Boolean
- #to_s ⇒ Object
- #with_tag(new_tag) ⇒ Object
Constructor Details
#initialize(protocol, registry, repository, tag) ⇒ DockerURI
Returns a new instance of DockerURI.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tagfish/docker_uri.rb', line 23 def initialize(protocol, registry, repository, tag) @protocol = protocol @registry = registry @repository = repository @tag = tag if registry.nil? @protocol = "https://" @registry = "index.docker.io" elsif protocol.nil? @protocol = "https://" end end |
Instance Attribute Details
#protocol ⇒ Object
Returns the value of attribute protocol.
18 19 20 |
# File 'lib/tagfish/docker_uri.rb', line 18 def protocol @protocol end |
#registry ⇒ Object
Returns the value of attribute registry.
19 20 21 |
# File 'lib/tagfish/docker_uri.rb', line 19 def registry @registry end |
#repository ⇒ Object
Returns the value of attribute repository.
20 21 22 |
# File 'lib/tagfish/docker_uri.rb', line 20 def repository @repository end |
#tag ⇒ Object
Returns the value of attribute tag.
21 22 23 |
# File 'lib/tagfish/docker_uri.rb', line 21 def tag @tag end |
Class Method Details
.parse(docker_string) ⇒ Object
13 14 15 16 |
# File 'lib/tagfish/docker_uri.rb', line 13 def self.parse(docker_string) match = docker_string.match(URI_PARSER) new(*match.captures) end |
Instance Method Details
#repo_and_tag ⇒ Object
37 38 39 |
# File 'lib/tagfish/docker_uri.rb', line 37 def repo_and_tag tag.nil? ? "#{repository}" : "#{repository}:#{tag}" end |
#tag? ⇒ Boolean
41 42 43 |
# File 'lib/tagfish/docker_uri.rb', line 41 def tag? not tag.nil? end |
#tagged_latest? ⇒ Boolean
45 46 47 |
# File 'lib/tagfish/docker_uri.rb', line 45 def tagged_latest? tag == 'latest' end |
#to_s ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/tagfish/docker_uri.rb', line 53 def to_s reg_sep = registry.nil? ? nil : "/" tag_sep = tag.nil? ? nil : ":" if registry == "index.docker.io" "#{repository}#{tag_sep}#{tag}" else "#{registry}#{reg_sep}#{repository}#{tag_sep}#{tag}" end end |
#with_tag(new_tag) ⇒ Object
49 50 51 |
# File 'lib/tagfish/docker_uri.rb', line 49 def with_tag(new_tag) self.class.new(protocol, registry, repository, new_tag) end |