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
Kazuhiko Shiozaki
gitlab-ce
Commits
d382335d
Commit
d382335d
authored
Dec 21, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add implementation of remaining methods in `StringPath`
parent
c184eeb8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
12 deletions
+57
-12
lib/gitlab/string_path.rb
lib/gitlab/string_path.rb
+14
-2
spec/lib/gitlab/string_path_spec.rb
spec/lib/gitlab/string_path_spec.rb
+43
-10
No files found.
lib/gitlab/string_path.rb
View file @
d382335d
...
...
@@ -43,12 +43,24 @@ module Gitlab
new
(
@path
.
sub
(
basename
,
''
))
end
def
descendants
return
[]
unless
directory?
children
=
@universe
.
select
{
|
entry
|
entry
=~
/^
#{
@path
}
.+/
}
children
.
map
{
|
path
|
new
(
path
)
}
end
def
children
descendants
.
select
{
|
descendant
|
descendant
.
parent
==
self
}
end
def
directories
raise
NotImplementedError
return
[]
unless
directory?
children
.
select
{
|
child
|
child
.
directory?
}
end
def
files
raise
NotImplementedError
return
[]
unless
directory?
children
.
select
{
|
child
|
child
.
file?
}
end
def
basename
...
...
spec/lib/gitlab/string_path_spec.rb
View file @
d382335d
...
...
@@ -16,7 +16,11 @@ describe Gitlab::StringPath do
end
def
path
(
example
)
described_class
.
new
(
example
.
metadata
[
:path
],
universe
)
string_path
(
example
.
metadata
[
:path
])
end
def
string_path
(
string_path
)
described_class
.
new
(
string_path
,
universe
)
end
describe
'/file/with/absolute_path'
,
path:
'/file/with/absolute_path'
do
...
...
@@ -47,14 +51,6 @@ describe Gitlab::StringPath do
it
{
is_expected
.
to
have_parent
}
describe
'#files'
do
subject
{
|
example
|
path
(
example
).
files
}
pending
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
pending
{
is_expected
.
to
be
eq
[
Gitlab
::
StringPath
.
new
(
'path/dir_1/file_1'
,
universe
),
Gitlab
::
StringPath
.
new
(
'path/dir_1/file_b'
,
universe
)]
}
end
describe
'#basename'
do
subject
{
|
example
|
path
(
example
).
basename
}
...
...
@@ -64,7 +60,44 @@ describe Gitlab::StringPath do
describe
'#parent'
do
subject
{
|
example
|
path
(
example
).
parent
}
it
{
is_expected
.
to
eq
Gitlab
::
StringPath
.
new
(
'path/'
,
universe
)
}
it
{
is_expected
.
to
eq
string_path
(
'path/'
)
}
end
describe
'#descendants'
do
subject
{
|
example
|
path
(
example
).
descendants
}
it
{
is_expected
.
to
be_an_instance_of
Array
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/file_1'
),
string_path
(
'path/dir_1/file_b'
),
string_path
(
'path/dir_1/subdir/'
),
string_path
(
'path/dir_1/subdir/subfile'
)
}
end
describe
'#children'
do
subject
{
|
example
|
path
(
example
).
children
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/file_1'
),
string_path
(
'path/dir_1/file_b'
),
string_path
(
'path/dir_1/subdir/'
)
}
end
describe
'#files'
do
subject
{
|
example
|
path
(
example
).
files
}
it
{
is_expected
.
to
all
(
be_file
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/file_1'
),
string_path
(
'path/dir_1/file_b'
)
}
end
describe
'#directories'
do
subject
{
|
example
|
path
(
example
).
directories
}
it
{
is_expected
.
to
all
(
be_directory
)
}
it
{
is_expected
.
to
all
(
be_an_instance_of
described_class
)
}
it
{
is_expected
.
to
contain_exactly
string_path
(
'path/dir_1/subdir/'
)
}
end
end
end
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