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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/config/entry/inheritable.rb')
-rw-r--r--lib/gitlab/config/entry/inheritable.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/config/entry/inheritable.rb b/lib/gitlab/config/entry/inheritable.rb
new file mode 100644
index 00000000000..91ca82e6338
--- /dev/null
+++ b/lib/gitlab/config/entry/inheritable.rb
@@ -0,0 +1,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