Method: DockerDistribution::Reference.parse

Defined in:
lib/docker_distribution/reference.rb

.parse(s) ⇒ Object

Parse parses s and returns a syntactically valid Reference.

If an error was encountered it is returned, along with a nil Reference.
NOTE: Parse will not handle short digests.

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/docker_distribution/reference.rb', line 39

def self.parse(s)
  matches = Regexp.reference_regexp.match(s)
  if matches.nil?
    raise NameEmpty if Helpers.empty?(s)
    raise NameContainsUppercase unless Regexp.reference_regexp.match(s.downcase).nil?

    raise ReferenceInvalidFormat
  end

  match_results = matches.to_a
  raise NameTooLong if match_results[1] && match_results[1].length > MAX_NAME_TOTAL_LENGTH

  repo = Repository.new
  name_match = Regexp.anchored_name_regexp.match(match_results[1])
  name_match_results = name_match&.to_a

  if name_match_results && name_match_results.length == 3
    repo.domain = name_match_results[1]
    repo.path = name_match_results[2]
  else
    repo.domain = nil
    repo.path = name_match_results[1]
  end

  ref = Reference.new(repo, match_results[2])

  unless Helpers.empty?(match_results[3])
    digest = Digest.parse!(match_results[3])
    ref.digest = digest.digest
  end

  r = get_best_reference_type(ref)
  raise NameEmpty if r.nil?

  r
end