BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e10dae3e
Commit
e10dae3e
authored
Apr 03, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code in container repository path class
parent
1a47986b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
path.rb
lib/container_registry/path.rb
+13
-10
path_spec.rb
spec/lib/container_registry/path_spec.rb
+8
-0
No files found.
lib/container_registry/path.rb
View file @
e10dae3e
...
...
@@ -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
spec/lib/container_registry/path_spec.rb
View file @
e10dae3e
...
...
@@ -3,6 +3,14 @@ require 'spec_helper'
describe
ContainerRegistry
::
Path
do
subject
{
described_class
.
new
(
path
)
}
describe
'#nodes'
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]
end
end
describe
'#components'
do
context
'when repository path is valid'
do
let
(
:path
)
{
'path/to/some/project'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment