summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config/entry/cache.rb
blob: 0a25057f482eb695515717270afc2d9328ae1692 (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
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module Entry
        ##
        # Entry that represents a cache configuration
        #
        class Cache < Node
          include Configurable
          include Attributable

          ALLOWED_KEYS = %i[key untracked paths policy].freeze
          DEFAULT_POLICY = 'pull-push'.freeze

          validations do
            validates :config, allowed_keys: ALLOWED_KEYS
            validates :policy, inclusion: { in: %w[pull-push push pull], message: 'should be pull-push, push, or pull' }, allow_blank: true
          end

          entry :key, Entry::Key,
            description: 'Cache key used to define a cache affinity.'

          entry :untracked, Entry::Boolean,
            description: 'Cache all untracked files.'

          entry :paths, Entry::Paths,
            description: 'Specify which paths should be cached across builds.'

          helpers :key

          attributes :policy

          def value
            result = super

            result[:key] = key_value
            result[:policy] = policy || DEFAULT_POLICY

            result
          end
        end
      end
    end
  end
end