mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-13 14:46:05 +10:00
`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.
36 lines
566 B
Ruby
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
|