Class: Gitlab::Ci::Build::Artifacts::Metadata
- Inherits:
-
Object
- Object
- Gitlab::Ci::Build::Artifacts::Metadata
- Defined in:
- lib/gitlab/ci/build/artifacts/metadata.rb,
lib/gitlab/ci/build/artifacts/metadata/entry.rb
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- ParserError =
Class.new(StandardError)
- InvalidStreamError =
Class.new(StandardError)
- VERSION_PATTERN =
/^[\w\s]+(\d+\.\d+\.\d+)/
- INVALID_PATH_PATTERN =
%r{(^\.?\.?/)|(/\.?\.?/)}
Instance Attribute Summary collapse
-
#full_version ⇒ Object
readonly
Returns the value of attribute full_version.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #errors ⇒ Object
- #find_entries! ⇒ Object
-
#initialize(stream, path, **opts) ⇒ Metadata
constructor
A new instance of Metadata.
- #to_entry ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(stream, path, **opts) ⇒ Metadata
Returns a new instance of Metadata.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 19 def initialize(stream, path, **opts) @stream = stream # Ensure to remove any ./ prefix from the path # so that the pattern matching will work as expected @path = path.gsub(%r{^\./}, '') @opts = opts @full_version = read_version end |
Instance Attribute Details
#full_version ⇒ Object (readonly)
Returns the value of attribute full_version.
17 18 19 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 17 def full_version @full_version end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 17 def path @path end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
17 18 19 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 17 def stream @stream end |
Instance Method Details
#errors ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 34 def errors gzip do |gz| read_string(gz) # version errors = read_string(gz) raise ParserError, 'Errors field not found!' unless errors begin Gitlab::Json.parse(errors) rescue JSON::ParserError raise ParserError, 'Invalid errors field!' end end end |
#find_entries! ⇒ Object
48 49 50 51 52 53 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 48 def find_entries! gzip do |gz| 2.times { read_string(gz) } # version and errors fields match_entries(gz) end end |
#to_entry ⇒ Object
55 56 57 58 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 55 def to_entry entries = find_entries! Entry.new(@path, entries) end |
#version ⇒ Object
30 31 32 |
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 30 def version @full_version.match(VERSION_PATTERN)[1] end |