Commit 44f9ec35 authored by Alex Kalderimis's avatar Alex Kalderimis

Remove unnecessary nil-checks

parent 9b260b67
...@@ -11,8 +11,6 @@ module Gitlab ...@@ -11,8 +11,6 @@ module Gitlab
segments = gl_repository&.split('-') segments = gl_repository&.split('-')
# gl_repository can either have 2 or 3 segments: # gl_repository can either have 2 or 3 segments:
# "wiki-1" is the older 2-segment format, where container is implied.
# "group-1-wiki" is the newer 3-segment format, including container information.
# #
# TODO: convert all 2-segment format to 3-segment: # TODO: convert all 2-segment format to 3-segment:
# https://gitlab.com/gitlab-org/gitlab/-/issues/219192 # https://gitlab.com/gitlab-org/gitlab/-/issues/219192
...@@ -28,6 +26,8 @@ module Gitlab ...@@ -28,6 +26,8 @@ module Gitlab
raise InvalidIdentifier, %Q(Invalid GL Repository "#{gl_repository}") raise InvalidIdentifier, %Q(Invalid GL Repository "#{gl_repository}")
end end
# The older 2-segment format, where the container is implied.
# eg. project-1, wiki-1
class TwoPartIdentifier < Identifier class TwoPartIdentifier < Identifier
def initialize(repo_type_name, container_id_str) def initialize(repo_type_name, container_id_str)
@container_id_str = container_id_str @container_id_str = container_id_str
...@@ -37,10 +37,12 @@ module Gitlab ...@@ -37,10 +37,12 @@ module Gitlab
private private
def container_class def container_class
repo_type&.container_class repo_type.container_class
end end
end end
# The newer 3-segment format, where the container is explicit
# eg. group-1-wiki, project-1-wiki
class ThreePartIdentifier < Identifier class ThreePartIdentifier < Identifier
def initialize(container_type, container_id_str, repo_type_name) def initialize(container_type, container_id_str, repo_type_name)
@container_id_str = container_id_str @container_id_str = container_id_str
...@@ -61,13 +63,11 @@ module Gitlab ...@@ -61,13 +63,11 @@ module Gitlab
end end
def repo_type def repo_type
strong_memoize(:repo_type) {Gitlab::GlRepository.types[repo_type_name] } strong_memoize(:repo_type) { Gitlab::GlRepository.types[repo_type_name] }
end end
def container def container
strong_memoize(:container) do strong_memoize(:container) { container_class.find_by_id(container_id) }
container_class&.find_by_id(container_id) if container_id
end
end end
def valid? def valid?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment