diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-28 14:34:56 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-28 14:34:56 +0200 |
commit | b15d9042e2688f29b002f90e0154e793ff1544ff (patch) | |
tree | 2c14369194518bcb2bbe96e1d568de0d75081d5d /lib/container_registry | |
parent | f09e3fe85116743c0cb537fb958a8b0ab1ad19fb (diff) | |
download | gitlab-ce-b15d9042e2688f29b002f90e0154e793ff1544ff.tar.gz |
Implement container repository path class
Diffstat (limited to 'lib/container_registry')
-rw-r--r-- | lib/container_registry/path.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/container_registry/path.rb b/lib/container_registry/path.rb new file mode 100644 index 00000000000..f32df1bc0d1 --- /dev/null +++ b/lib/container_registry/path.rb @@ -0,0 +1,29 @@ +module ContainerRegistry + class Path + InvalidRegistryPathError = Class.new(StandardError) + + def initialize(name) + @nodes = name.to_s.split('/') + end + + def valid? + @nodes.size > 1 && + @nodes.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED + end + + def components + raise InvalidRegistryPathError unless valid? + + @components ||= @nodes.size.downto(2).map do |length| + @nodes.take(length).join('/') + end + end + + def repository_project + @project ||= Project.where_full_path_in(components.first(3))&.first + end + + def repository_name + end + end +end |