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
518b2062
Commit
518b2062
authored
Dec 19, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `parent` iteration implementation to `StringPath`
parent
80a71576
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
lib/gitlab/string_path.rb
lib/gitlab/string_path.rb
+9
-2
spec/lib/gitlab/string_path_spec.rb
spec/lib/gitlab/string_path_spec.rb
+10
-1
No files found.
lib/gitlab/string_path.rb
View file @
518b2062
...
@@ -35,11 +35,12 @@ module Gitlab
...
@@ -35,11 +35,12 @@ module Gitlab
end
end
def
has_parent?
def
has_parent?
raise
NotImplementedError
@universe
.
include?
(
@path
.
sub
(
basename
,
''
))
end
end
def
parent
def
parent
raise
NotImplementedError
return
nil
unless
has_parent?
new
(
@path
.
sub
(
basename
,
''
))
end
end
def
directories
def
directories
...
@@ -58,5 +59,11 @@ module Gitlab
...
@@ -58,5 +59,11 @@ module Gitlab
def
==
(
other
)
def
==
(
other
)
@path
==
other
.
path
&&
@universe
==
other
.
universe
@path
==
other
.
path
&&
@universe
==
other
.
universe
end
end
private
def
new
(
path
)
self
.
class
.
new
(
path
,
@universe
)
end
end
end
end
end
spec/lib/gitlab/string_path_spec.rb
View file @
518b2062
...
@@ -19,6 +19,7 @@ describe Gitlab::StringPath do
...
@@ -19,6 +19,7 @@ describe Gitlab::StringPath do
it
{
is_expected
.
to
be_absolute
}
it
{
is_expected
.
to
be_absolute
}
it
{
is_expected
.
to_not
be_relative
}
it
{
is_expected
.
to_not
be_relative
}
it
{
is_expected
.
to
be_file
}
it
{
is_expected
.
to
be_file
}
it
{
is_expected
.
to_not
have_parent
}
describe
'#basename'
do
describe
'#basename'
do
subject
{
described_class
.
new
(
'/file/with/absolute_path'
,
universe
).
basename
}
subject
{
described_class
.
new
(
'/file/with/absolute_path'
,
universe
).
basename
}
...
@@ -32,9 +33,13 @@ describe Gitlab::StringPath do
...
@@ -32,9 +33,13 @@ describe Gitlab::StringPath do
it
{
is_expected
.
to
be_directory
}
it
{
is_expected
.
to
be_directory
}
it
{
is_expected
.
to
be_relative
}
it
{
is_expected
.
to
be_relative
}
it
{
is_expected
.
to_not
have_parent
}
end
end
describe
'path/dir_1/'
do
describe
'path/dir_1/'
do
subject
{
described_class
.
new
(
'path/dir_1/'
,
universe
)
}
it
{
is_expected
.
to
have_parent
}
describe
'#files'
do
describe
'#files'
do
subject
{
described_class
.
new
(
'path/dir_1/'
,
universe
).
files
}
subject
{
described_class
.
new
(
'path/dir_1/'
,
universe
).
files
}
...
@@ -45,8 +50,12 @@ describe Gitlab::StringPath do
...
@@ -45,8 +50,12 @@ describe Gitlab::StringPath do
describe
'#basename'
do
describe
'#basename'
do
subject
{
described_class
.
new
(
'path/dir_1/'
,
universe
).
basename
}
subject
{
described_class
.
new
(
'path/dir_1/'
,
universe
).
basename
}
it
{
is_expected
.
to
eq
'dir_1/'
}
it
{
is_expected
.
to
eq
'dir_1/'
}
end
end
describe
'#parent'
do
subject
{
described_class
.
new
(
'path/dir_1/'
,
universe
).
parent
}
it
{
is_expected
.
to
eq
Gitlab
::
StringPath
.
new
(
'path/'
,
universe
)
}
end
end
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