Welcome to mirror list, hosted at ThFree Co, Russian Federation.

artifactable.rb « ci « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24df86dbc3c3619cfb9e602f9dbe23e85fa0fc07 (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
# frozen_string_literal: true

module Ci
  module Artifactable
    extend ActiveSupport::Concern

    NotSupportedAdapterError = Class.new(StandardError)

    FILE_FORMAT_ADAPTERS = {
      gzip: Gitlab::Ci::Build::Artifacts::Adapters::GzipStream,
      raw: Gitlab::Ci::Build::Artifacts::Adapters::RawStream
    }.freeze

    included do
      enum file_format: {
        raw: 1,
        zip: 2,
        gzip: 3
      }, _suffix: true

      scope :expired, -> (limit) { where('expire_at < ?', Time.current).limit(limit) }
    end

    def each_blob(&blk)
      unless file_format_adapter_class
        raise NotSupportedAdapterError, 'This file format requires a dedicated adapter'
      end

      file.open do |stream|
        file_format_adapter_class.new(stream).each_blob(&blk)
      end
    end

    private

    def file_format_adapter_class
      FILE_FORMAT_ADAPTERS[file_format.to_sym]
    end
  end
end