Files
gitlabhq/lib/gitlab/string_path.rb
T
Grzegorz Bizon f5d5308658 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.
2016-01-14 12:48:12 +01:00

36 lines
566 B
Ruby

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