Class: OCIRegistry::URI
- Inherits:
-
URI::Generic
- Object
- URI::Generic
- OCIRegistry::URI
- Defined in:
- lib/oci_registry/uri.rb
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#host ⇒ Object
Returns the value of attribute host.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#tag ⇒ Object
Returns the value of attribute tag.
Instance Method Summary collapse
-
#initialize(uri) ⇒ URI
constructor
A new instance of URI.
-
#to_s ⇒ Object
Allow for heroku/ruby heroku/ruby:2.7.2 heroku/ruby@sha256:1234abcd docker://docker.io/heroku/ruby docker://docker.io/heroku/ruby:2.7.2.
Constructor Details
#initialize(uri) ⇒ URI
Returns a new instance of URI.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/oci_registry/uri.rb', line 8 def initialize(uri) raise ArgumentError, 'OCIRegistry::URI->URI cannot be nil' if uri.nil? raise ArgumentError, 'OCIRegistry::URI->URI must be a String' unless uri.is_a?(String) # TODO: This addition makes this less an OCI URI library and more a CNB Builder Resource Library # Handle the case where the URI is just ./eol-buildpack/ which is a local path. @repository = uri and @scheme = 'local' and return if uri.start_with?('./') # Call the parent class constructor @parsed = ::URI.parse(uri) # Use `::URI` to refer to Ruby's URI class # Ensure the scheme is docker unless ['docker', 'oci'].include?(@parsed.scheme) raise ArgumentError, 'URI must start with (docker|oci)://' end # Extract repository, tag, and digest from the URI's path @scheme = @parsed.scheme @host = @parsed.host @repository, tag_or_digest = @parsed.path.split('@').first.split(':') # Remove any leading slashes from the repository @repository = @repository.sub(%r{^/*}, '') @digest = @parsed.path.split('@')[1] @tag = tag_or_digest unless @digest end |
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest.
6 7 8 |
# File 'lib/oci_registry/uri.rb', line 6 def digest @digest end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/oci_registry/uri.rb', line 6 def host @host end |
#repository ⇒ Object
Returns the value of attribute repository.
6 7 8 |
# File 'lib/oci_registry/uri.rb', line 6 def repository @repository end |
#scheme ⇒ Object
Returns the value of attribute scheme.
6 7 8 |
# File 'lib/oci_registry/uri.rb', line 6 def scheme @scheme end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/oci_registry/uri.rb', line 6 def tag @tag end |
Instance Method Details
#to_s ⇒ Object
Allow for heroku/ruby heroku/ruby:2.7.2 heroku/ruby@sha256:1234abcd docker://docker.io/heroku/ruby docker://docker.io/heroku/ruby:2.7.2
40 41 42 43 44 45 46 47 48 |
# File 'lib/oci_registry/uri.rb', line 40 def to_s base = "" base += "#{@scheme}://" if @scheme base += "#{@host}/" if @host base += "#{@repository}" if @repository base += ":#{@tag}" if @tag base += "@#{@digest}" if @digest base end |