Class: Gitlab::Ci::Build::Artifacts::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/build/artifacts/path.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Path

Returns a new instance of Path.



8
9
10
# File 'lib/gitlab/ci/build/artifacts/path.rb', line 8

def initialize(path)
  @path = path.dup.force_encoding('UTF-8')
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/gitlab/ci/build/artifacts/path.rb', line 16

def directory?
  @path.end_with?('/')
end

#nameObject



20
21
22
# File 'lib/gitlab/ci/build/artifacts/path.rb', line 20

def name
  @path.split('/').last.to_s
end

#nodesObject



24
25
26
# File 'lib/gitlab/ci/build/artifacts/path.rb', line 24

def nodes
  @path.count('/')
end

#to_sObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/ci/build/artifacts/path.rb', line 28

def to_s
  @path.tap do |path|
    unless nonzero?
      raise ArgumentError, 'Path contains zero byte character!'
    end

    unless utf8?
      raise ArgumentError, 'Path contains non-UTF-8 byte sequence!'
    end
  end
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/gitlab/ci/build/artifacts/path.rb', line 12

def valid?
  nonzero? && utf8?
end