Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
f948c007
Commit
f948c007
authored
Jan 04, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not depend on universe when checking parent in `StringPath`
parent
a7f99b67
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
lib/gitlab/string_path.rb
lib/gitlab/string_path.rb
+12
-3
spec/lib/gitlab/string_path_spec.rb
spec/lib/gitlab/string_path_spec.rb
+16
-1
No files found.
lib/gitlab/string_path.rb
View file @
f948c007
...
...
@@ -7,6 +7,7 @@ module Gitlab
#
class
StringPath
attr_reader
:path
,
:universe
attr_accessor
:name
def
initialize
(
path
,
universe
,
metadata
=
[])
@path
=
sanitize
(
path
)
...
...
@@ -35,7 +36,7 @@ module Gitlab
end
def
has_parent?
@universe
.
include?
(
@path
.
sub
(
basename
,
''
))
nodes
>
1
end
def
parent
...
...
@@ -48,7 +49,7 @@ module Gitlab
end
def
name
@path
.
split
(
::
File
::
SEPARATOR
).
last
@
name
||
@
path
.
split
(
::
File
::
SEPARATOR
).
last
end
def
has_descendants?
...
...
@@ -75,7 +76,11 @@ module Gitlab
end
def
directories!
@path
=~
%r{^
\.
/[^/]/}
?
directories
.
prepend
(
parent
)
:
directories
return
directories
unless
has_parent?
&&
directory?
dotted_parent
=
parent
dotted_parent
.
name
=
'..'
directories
.
prepend
(
dotted_parent
)
end
def
files
...
...
@@ -88,6 +93,10 @@ module Gitlab
@metadata
[
index
]
end
def
nodes
@path
.
count
(
'/'
)
+
(
file?
?
1
:
0
)
end
def
==
(
other
)
@path
==
other
.
path
&&
@universe
==
other
.
universe
end
...
...
spec/lib/gitlab/string_path_spec.rb
View file @
f948c007
...
...
@@ -30,7 +30,7 @@ describe Gitlab::StringPath do
it
{
is_expected
.
to
be_absolute
}
it
{
is_expected
.
to_not
be_relative
}
it
{
is_expected
.
to
be_file
}
it
{
is_expected
.
to
_not
have_parent
}
it
{
is_expected
.
to
have_parent
}
it
{
is_expected
.
to_not
have_descendants
}
describe
'#basename'
do
...
...
@@ -140,6 +140,21 @@ describe Gitlab::StringPath do
end
end
describe
'#nodes'
,
path:
'./'
do
subject
{
|
example
|
path
(
example
).
nodes
}
it
{
is_expected
.
to
eq
1
}
end
describe
'#nodes'
,
path:
'./test'
do
subject
{
|
example
|
path
(
example
).
nodes
}
it
{
is_expected
.
to
eq
2
}
end
describe
'#nodes'
,
path:
'./test/'
do
subject
{
|
example
|
path
(
example
).
nodes
}
it
{
is_expected
.
to
eq
2
}
end
describe
'#metadata'
do
let
(
:universe
)
do
[
'path/'
,
'path/file1'
,
'path/file2'
]
...
...
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