summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/string_path.rb10
1 files changed, 9 insertions, 1 deletions
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? }