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