Class: Gitlab::Ci::Build::Artifacts::Metadata::Entry
- Inherits:
-
Object
- Object
- Gitlab::Ci::Build::Artifacts::Metadata::Entry
- Defined in:
- lib/gitlab/ci/build/artifacts/metadata/entry.rb
Overview
Class that represents an entry (path and metadata) to a file or directory in GitLab CI Build Artifacts binary file / archive
This is IO-operations safe class, that does similar job to Ruby’s Pathname but without the risk of accessing filesystem.
This class is working only with UTF-8 encoded paths.
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
- #name ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #basename ⇒ Object
- #blank_node? ⇒ Boolean
- #blob ⇒ Object
- #children ⇒ Object
- #directories(opts = {}) ⇒ Object
- #directory? ⇒ Boolean
- #exists? ⇒ Boolean
- #file? ⇒ Boolean
- #files ⇒ Object
- #has_parent? ⇒ Boolean
-
#initialize(path, entries) ⇒ Entry
constructor
A new instance of Entry.
- #inspect ⇒ Object
- #metadata ⇒ Object
- #nodes ⇒ Object
- #parent ⇒ Object
-
#path ⇒ Object
rubocop: enable CodeReuse/ActiveRecord.
- #to_s ⇒ Object
-
#total_size ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
Constructor Details
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
18 19 20 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 18 def entries @entries end |
#name ⇒ Object
56 57 58 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 56 def name @name || @path.name end |
Instance Method Details
#==(other) ⇒ Object
118 119 120 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 118 def ==(other) path == other.path && @entries == other.entries end |
#basename ⇒ Object
52 53 54 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 52 def basename directory? && !blank_node? ? name + '/' : name end |
#blank_node? ⇒ Boolean
93 94 95 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 93 def blank_node? @path.to_s.empty? # "" is considered to be './' end |
#blob ⇒ Object
36 37 38 39 40 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 36 def blob return unless file? @blob ||= Blob.decorate(::Ci::ArtifactBlob.new(self), nil) end |
#children ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 60 def children return [] unless directory? return @children if @children child_pattern = %r{^#{Regexp.escape(@path.to_s)}[^/]+/?$} @children = select_entries { |path| path =~ child_pattern } end |
#directories(opts = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 68 def directories(opts = {}) return [] unless directory? dirs = children.select(&:directory?) return dirs unless has_parent? && opts[:parent] dotted_parent = parent dotted_parent.name = '..' dirs.prepend(dotted_parent) end |
#directory? ⇒ Boolean
28 29 30 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 28 def directory? blank_node? || @path.directory? end |
#exists? ⇒ Boolean
97 98 99 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 97 def exists? blank_node? || @entries.include?(@path.to_s) end |
#file? ⇒ Boolean
32 33 34 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 32 def file? !directory? end |
#files ⇒ Object
79 80 81 82 83 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 79 def files return [] unless directory? children.select(&:file?) end |
#has_parent? ⇒ Boolean
42 43 44 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 42 def has_parent? nodes > 0 end |
#inspect ⇒ Object
122 123 124 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 122 def inspect "#{self.class.name}: #{self}" end |
#metadata ⇒ Object
85 86 87 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 85 def @entries[@path.to_s] || {} end |
#nodes ⇒ Object
89 90 91 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 89 def nodes @path.nodes + (file? ? 1 : 0) end |
#parent ⇒ Object
46 47 48 49 50 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 46 def parent return unless has_parent? self.class.new(@path.to_s.chomp(basename), @entries) end |
#path ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
110 111 112 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 110 def path @path.to_s end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 114 def to_s @path.to_s end |
#total_size ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
102 103 104 105 106 107 |
# File 'lib/gitlab/ci/build/artifacts/metadata/entry.rb', line 102 def total_size descendant_pattern = /^#{Regexp.escape(@path.to_s)}/ entries.sum do |path, entry| (entry[:size] if descendant_pattern.match?(path)).to_i end end |