blob: 3aa6200b572975fc148ba97e51d5737016fb4003 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
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
attr_reader :path, :universe
def initialize(path, universe)
@path = path
@universe = universe
end
def to_s
@path
end
def absolute?
@path.start_with?('/')
end
def relative?
!absolute?
end
def directory?
@path.end_with?('/')
end
def file?
!directory?
end
def has_parent?
raise NotImplementedError
end
def parent
raise NotImplementedError
end
def directories
raise NotImplementedError
end
def files
raise NotImplementedError
end
def basename
name = @path.split(::File::SEPARATOR).last
directory? ? name + ::File::SEPARATOR : name
end
def ==(other)
@path == other.path && @universe == other.universe
end
end
end
|