summaryrefslogtreecommitdiff
path: root/lib/gitlab/config/entry/inheritable.rb
blob: 91ca82e633884ab96a691176157b8abf37218fe1 (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 Gitlab
  module Config
    module Entry
      ##
      # Entry that represents an inheritable configs.
      #
      module Inheritable
        InheritError = Class.new(Gitlab::Config::Loader::FormatError)

        def compose!(deps = nil, &blk)
          super(deps, &blk)

          inherit!(deps)
        end

        private

        # We inherit config entries from `default:`
        # if the entry has the `inherit: true` flag set
        def inherit!(deps)
          return unless deps

          self.class.nodes.each do |key, factory|
            next unless factory.inheritable?

            new_entry = overwrite_entry(deps, key, self[key])

            entries[key] = new_entry if new_entry&.specified?
          end
        end

        def overwrite_entry(deps, key, current_entry)
          raise NotImplementedError
        end
      end
    end
  end
end