diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2015-12-22 11:05:22 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-01-14 12:48:13 +0100 |
commit | b19e958d86f5363057f006c8dbf9a8e8762618b9 (patch) | |
tree | 2f0239396ee98841374c99f73439c81a0939dad9 /lib | |
parent | aae674c3a2bbe3e3c2303be0174fda785abb11d4 (diff) | |
download | gitlab-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.rb | 10 |
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? } |