From f5d530865875440d69217cf249715bffaa3d11b8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 18 Dec 2015 11:59:10 +0100 Subject: Add implementation of StringPath class `StringPath` class is something similar to Ruby's `Pathname` class, but does not involve any IO operations. `StringPath` objects require passing string representation of path, and array of paths that represents universe to constructor to be intantiated. --- lib/gitlab/string_path.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/gitlab/string_path.rb (limited to 'lib') diff --git a/lib/gitlab/string_path.rb b/lib/gitlab/string_path.rb new file mode 100644 index 00000000000..be65b41dff5 --- /dev/null +++ b/lib/gitlab/string_path.rb @@ -0,0 +1,35 @@ +module Gitlab + ## + # Class that represents a path to a file or directory + # + # This is IO-operations safe class, that does similar job to + # Ruby's Pathname but without the risk of accessing filesystem. + # + # + class StringPath + def initialize(path, universe) + @path = path + @universe = universe + end + + def absolute? + @path.start_with?('/') + end + + def relative? + !absolute? + end + + def directory? + @path.end_with?('/') + end + + def file? + !directory? + end + + def to_s + @path + end + end +end -- cgit v1.2.1