summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2015-12-18 12:32:21 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-01-14 12:48:12 +0100
commit73d2c7a553ca239cdce04af793992fd579ad3e4b (patch)
treea679c1366a4b01e12da0579916082e1bb7853f07
parentf5d530865875440d69217cf249715bffaa3d11b8 (diff)
downloadgitlab-ce-73d2c7a553ca239cdce04af793992fd579ad3e4b.tar.gz
Add new methods to StringPath
-rw-r--r--lib/gitlab/string_path.rb19
-rw-r--r--spec/lib/gitlab/string_path_spec.rb33
2 files changed, 49 insertions, 3 deletions
diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb
index be65b41dff5..9ccf54bd62f 100644
--- a/lib/gitlab/string_path.rb
+++ b/lib/gitlab/string_path.rb
@@ -7,11 +7,17 @@ module Gitlab
#
#
class StringPath
+ attr_reader :path, :universe
+
def initialize(path, universe)
@path = path
@universe = universe
end
+ def to_s
+ @path
+ end
+
def absolute?
@path.start_with?('/')
end
@@ -28,8 +34,17 @@ module Gitlab
!directory?
end
- def to_s
- @path
+ def files
+ raise NotImplementedError
+ end
+
+ def basename
+ name = @path.split(::File::SEPARATOR).last
+ directory? ? name + ::File::SEPARATOR : name
+ end
+
+ def ==(other)
+ @path == other.path && @universe == other.universe
end
end
end
diff --git a/spec/lib/gitlab/string_path_spec.rb b/spec/lib/gitlab/string_path_spec.rb
index 14a08bcb49b..6e75e1f3ced 100644
--- a/spec/lib/gitlab/string_path_spec.rb
+++ b/spec/lib/gitlab/string_path_spec.rb
@@ -2,8 +2,10 @@ require 'spec_helper'
describe Gitlab::StringPath do
let(:universe) do
- ['path/dir_1/',
+ ['path/',
+ 'path/dir_1/',
'path/dir_1/file_1',
+ 'path/dir_1/file_b',
'path/second_dir',
'path/second_dir/dir_3/file_2',
'path/second_dir/dir_3/file_3',
@@ -17,5 +19,34 @@ describe Gitlab::StringPath do
it { is_expected.to be_absolute }
it { is_expected.to_not be_relative }
it { is_expected.to be_file }
+
+ describe '#basename' do
+ subject { described_class.new('/file/with/absolute_path', universe).basename }
+
+ it { is_expected.to eq 'absolute_path' }
+ end
+ end
+
+ describe 'path/' do
+ subject { described_class.new('path/', universe) }
+
+ it { is_expected.to be_directory }
+ it { is_expected.to be_relative }
+ end
+
+ describe 'path/dir_1/' do
+ describe '#files' do
+ subject { described_class.new('path/dir_1/', universe).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 { described_class.new('path/dir_1/', universe).basename }
+
+ it { is_expected.to eq 'dir_1/' }
+ end
end
end