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

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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, %Q(Invalid GL Repository "#{gl_repository}")
end

Instance Method Details

#containerObject


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

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

#repo_typeObject


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

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

#valid?Boolean

Returns:

  • (Boolean)

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

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