summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-04-03 11:42:37 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-04-03 11:44:16 +0200
commite10dae3e3c2a5fb6077244c72e44c912b7281349 (patch)
treeb7189fb41ba3d99f6fe1fc22071177d6339176d0 /lib
parent1a47986b3d7cd8e6d5bdbfbc20a841cf5586f773 (diff)
downloadgitlab-ce-e10dae3e3c2a5fb6077244c72e44c912b7281349.tar.gz
Improve code in container repository path class
Diffstat (limited to 'lib')
-rw-r--r--lib/container_registry/path.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/container_registry/path.rb b/lib/container_registry/path.rb
index 6e8d62b77c7..f76c6489381 100644
--- a/lib/container_registry/path.rb
+++ b/lib/container_registry/path.rb
@@ -14,24 +14,23 @@ module ContainerRegistry
def initialize(path)
@path = path
- @nodes = path.to_s.split('/')
- end
-
- def to_s
- @path
end
def valid?
@path =~ Gitlab::Regex.container_repository_name_regex &&
- @nodes.size > 1 &&
- @nodes.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED
+ nodes.size > 1 &&
+ nodes.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED
+ end
+
+ def nodes
+ @nodes ||= @path.to_s.split('/')
end
def components
raise InvalidRegistryPathError unless valid?
- @components ||= @nodes.size.downto(2).map do |length|
- @nodes.take(length).join('/')
+ @components ||= nodes.size.downto(2).map do |length|
+ nodes.take(length).join('/')
end
end
@@ -51,7 +50,7 @@ module ContainerRegistry
end
def repository_project
- @project ||= Project.where_full_path_in(components.first(3))&.first
+ @project ||= Project.where_full_path_in(components.first(3)).first
end
def repository_name
@@ -59,5 +58,9 @@ module ContainerRegistry
@path.remove(%r(^?#{Regexp.escape(repository_project.full_path)}/?))
end
+
+ def to_s
+ @path
+ end
end
end