Class: Gitlab::GlRepository::Identifier

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/gl_repository/identifier.rb

Direct Known Subclasses

ThreePartIdentifier, TwoPartIdentifier

Defined Under Namespace

Classes: ThreePartIdentifier, TwoPartIdentifier

Constant Summary collapse

InvalidIdentifier =
Class.new(ArgumentError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(gl_repository) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/gl_repository/identifier.rb', line 10

def self.parse(gl_repository)
  segments = gl_repository&.split('-')

  # gl_repository can either have 2 or 3 segments:
  #
  # TODO: convert all 2-segment format to 3-segment:
  # https://gitlab.com/gitlab-org/gitlab/-/issues/219192
  identifier = case segments&.size
               when 2
                 TwoPartIdentifier.new(*segments)
               when 3
                 ThreePartIdentifier.new(*segments)
               end

  return identifier if identifier&.valid?

  raise InvalidIdentifier, %(Invalid GL Repository "#{gl_repository}")
end

Instance Method Details

#containerObject



70
71
72
# File 'lib/gitlab/gl_repository/identifier.rb', line 70

def container
  strong_memoize(:container) { container_class.find_by_id(container_id) }
end

#repo_typeObject



66
67
68
# File 'lib/gitlab/gl_repository/identifier.rb', line 66

def repo_type
  strong_memoize(:repo_type) { Gitlab::GlRepository.types[repo_type_name] }
end

#valid?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/gitlab/gl_repository/identifier.rb', line 74

def valid?
  repo_type.present? && container_class.present? && container_id&.positive?
end