BigW Consortium Gitlab

Commit 518b2062 by Grzegorz Bizon

Add `parent` iteration implementation to `StringPath`

parent 80a71576
...@@ -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
...@@ -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
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