BigW Consortium Gitlab

Commit 518b2062 by Grzegorz Bizon

Add `parent` iteration implementation to `StringPath`

parent 80a71576
......@@ -35,11 +35,12 @@ module Gitlab
end
def has_parent?
raise NotImplementedError
@universe.include?(@path.sub(basename, ''))
end
def parent
raise NotImplementedError
return nil unless has_parent?
new(@path.sub(basename, ''))
end
def directories
......@@ -58,5 +59,11 @@ module Gitlab
def ==(other)
@path == other.path && @universe == other.universe
end
private
def new(path)
self.class.new(path, @universe)
end
end
end
......@@ -19,6 +19,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 }
describe '#basename' do
subject { described_class.new('/file/with/absolute_path', universe).basename }
......@@ -32,9 +33,13 @@ describe Gitlab::StringPath do
it { is_expected.to be_directory }
it { is_expected.to be_relative }
it { is_expected.to_not have_parent }
end
describe 'path/dir_1/' do
subject { described_class.new('path/dir_1/', universe) }
it { is_expected.to have_parent }
describe '#files' do
subject { described_class.new('path/dir_1/', universe).files }
......@@ -45,8 +50,12 @@ describe Gitlab::StringPath do
describe '#basename' do
subject { described_class.new('path/dir_1/', universe).basename }
it { is_expected.to eq 'dir_1/' }
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
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