Commit 97c6cf59 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Swap method names in containe registry path class

parent 7cf91f7b
...@@ -18,19 +18,19 @@ module ContainerRegistry ...@@ -18,19 +18,19 @@ module ContainerRegistry
def valid? def valid?
@path =~ Gitlab::Regex.container_repository_name_regex && @path =~ Gitlab::Regex.container_repository_name_regex &&
nodes.size > 1 && components.size > 1 &&
nodes.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED components.size < Namespace::NUMBER_OF_ANCESTORS_ALLOWED
end end
def nodes def components
@nodes ||= @path.to_s.split('/') @components ||= @path.to_s.split('/')
end end
def components def nodes
raise InvalidRegistryPathError unless valid? raise InvalidRegistryPathError unless valid?
@components ||= nodes.size.downto(2).map do |length| @nodes ||= components.size.downto(2).map do |length|
nodes.take(length).join('/') components.take(length).join('/')
end end
end end
...@@ -50,7 +50,7 @@ module ContainerRegistry ...@@ -50,7 +50,7 @@ module ContainerRegistry
end end
def repository_project def repository_project
@project ||= Project.where_full_path_in(components.first(3)).first @project ||= Project.where_full_path_in(nodes.first(3)).first
end end
def repository_name def repository_name
......
...@@ -3,22 +3,22 @@ require 'spec_helper' ...@@ -3,22 +3,22 @@ require 'spec_helper'
describe ContainerRegistry::Path do describe ContainerRegistry::Path do
subject { described_class.new(path) } subject { described_class.new(path) }
describe '#nodes' do describe '#components' do
let(:path) { 'path/to/some/project' } let(:path) { 'path/to/some/project' }
it 'splits elements by a forward slash' do it 'splits components by a forward slash' do
expect(subject.nodes).to eq %w[path to some project] expect(subject.components).to eq %w[path to some project]
end end
end end
describe '#components' do describe '#nodes' do
context 'when repository path is valid' do context 'when repository path is valid' do
let(:path) { 'path/to/some/project' } let(:path) { 'path/to/some/project' }
it 'return all project-like components in reverse order' do it 'return all project path like node in reverse order' do
expect(subject.components).to eq %w[path/to/some/project expect(subject.nodes).to eq %w[path/to/some/project
path/to/some path/to/some
path/to] path/to]
end end
end end
...@@ -26,7 +26,7 @@ describe ContainerRegistry::Path do ...@@ -26,7 +26,7 @@ describe ContainerRegistry::Path do
let(:path) { '' } let(:path) { '' }
it 'rasises en error' do it 'rasises en error' do
expect { subject.components } expect { subject.nodes }
.to raise_error described_class::InvalidRegistryPathError .to raise_error described_class::InvalidRegistryPathError
end end
end end
......
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