summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2015-12-22 11:05:22 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-01-14 12:48:13 +0100
commitb19e958d86f5363057f006c8dbf9a8e8762618b9 (patch)
tree2f0239396ee98841374c99f73439c81a0939dad9
parentaae674c3a2bbe3e3c2303be0174fda785abb11d4 (diff)
downloadgitlab-ce-b19e958d86f5363057f006c8dbf9a8e8762618b9.tar.gz
Add support for parent directories in `StringPath`
This support is not completed though, as parent directory that is first in collection returned by `directories!` is not iterable yet.
-rw-r--r--app/views/projects/artifacts/_tree_directory.html.haml4
-rw-r--r--app/views/projects/artifacts/browse.html.haml2
-rw-r--r--lib/gitlab/string_path.rb10
-rw-r--r--spec/lib/gitlab/string_path_spec.rb18
4 files changed, 26 insertions, 8 deletions
diff --git a/app/views/projects/artifacts/_tree_directory.html.haml b/app/views/projects/artifacts/_tree_directory.html.haml
index ec68c45865e..481a2cb072f 100644
--- a/app/views/projects/artifacts/_tree_directory.html.haml
+++ b/app/views/projects/artifacts/_tree_directory.html.haml
@@ -1,6 +1,6 @@
%tr{ class: 'tree-item' }
%td.tree-item-file-name
- = tree_icon('folder', '755', directory.basename)
+ = tree_icon('folder', '755', directory.name)
%span.str-truncated
- = link_to directory.basename, browse_namespace_project_build_artifacts_path(@project.namespace, @project, @build, path: directory.path)
+ = link_to directory.name, browse_namespace_project_build_artifacts_path(@project.namespace, @project, @build, path: directory.path)
%td
diff --git a/app/views/projects/artifacts/browse.html.haml b/app/views/projects/artifacts/browse.html.haml
index ddca02d2bed..141fea9a6d4 100644
--- a/app/views/projects/artifacts/browse.html.haml
+++ b/app/views/projects/artifacts/browse.html.haml
@@ -16,5 +16,5 @@
%tr
%th Name
%th Download
- = render partial: 'tree_directory', collection: @path.directories, as: :directory
+ = render partial: 'tree_directory', collection: @path.directories!, as: :directory
= render partial: 'tree_file', collection: @path.files, as: :file
diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb
index d165829132a..493fceb256d 100644
--- a/lib/gitlab/string_path.rb
+++ b/lib/gitlab/string_path.rb
@@ -5,6 +5,7 @@ module Gitlab
# This is IO-operations safe class, that does similar job to
# Ruby's Pathname but without the risk of accessing filesystem.
#
+ # TODO: better support for './' and '../'
#
class StringPath
attr_reader :path, :universe
@@ -45,10 +46,13 @@ module Gitlab
end
def basename
- name = @path.split(::File::SEPARATOR).last
directory? ? name + ::File::SEPARATOR : name
end
+ def name
+ @path.split(::File::SEPARATOR).last
+ end
+
def has_descendants?
descendants.any?
end
@@ -68,6 +72,10 @@ module Gitlab
children.select { |child| child.directory? }
end
+ def directories!
+ has_parent? ? directories.prepend(new(@path + '../')) : directories
+ end
+
def files
return [] unless directory?
children.select { |child| child.file? }
diff --git a/spec/lib/gitlab/string_path_spec.rb b/spec/lib/gitlab/string_path_spec.rb
index 7ee69c7d3cb..c1722977576 100644
--- a/spec/lib/gitlab/string_path_spec.rb
+++ b/spec/lib/gitlab/string_path_spec.rb
@@ -50,18 +50,20 @@ describe Gitlab::StringPath do
describe 'path/dir_1/', path: 'path/dir_1/' do
subject { |example| path(example) }
-
it { is_expected.to have_parent }
describe '#basename' do
subject { |example| path(example).basename }
-
it { is_expected.to eq 'dir_1/' }
end
+ describe '#name' do
+ subject { |example| path(example).name }
+ it { is_expected.to eq 'dir_1' }
+ end
+
describe '#parent' do
subject { |example| path(example).parent }
-
it { is_expected.to eq string_path('path/') }
end
@@ -101,6 +103,15 @@ describe Gitlab::StringPath do
it { is_expected.to all(be_an_instance_of described_class) }
it { is_expected.to contain_exactly string_path('path/dir_1/subdir/') }
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/'),
+ string_path('path/dir_1/../') }
+ end
end
describe './', path: './' do
@@ -118,7 +129,6 @@ describe Gitlab::StringPath do
describe '#children' do
subject { |example| path(example).children }
-
it { expect(subject.count).to eq 3 }
end
end