diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-28 18:06:15 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-28 18:06:15 +0000 |
commit | 7515ec41c527c62bfd56f46e388cf6d9fe06479f (patch) | |
tree | 614b555ec428b7eac4b836473d43516c41f9da46 /lib/gitlab/config | |
parent | a77db6bc47d8cdd9edae2ec22f640821d0794404 (diff) | |
download | gitlab-ce-7515ec41c527c62bfd56f46e388cf6d9fe06479f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/config')
-rw-r--r-- | lib/gitlab/config/entry/factory.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/config/entry/inheritable.rb | 40 |
2 files changed, 53 insertions, 7 deletions
diff --git a/lib/gitlab/config/entry/factory.rb b/lib/gitlab/config/entry/factory.rb index 8f1f4a81bb5..7c5ffaa7621 100644 --- a/lib/gitlab/config/entry/factory.rb +++ b/lib/gitlab/config/entry/factory.rb @@ -9,10 +9,12 @@ module Gitlab class Factory InvalidFactory = Class.new(StandardError) - def initialize(entry) - @entry = entry + attr_reader :entry_class + + def initialize(entry_class) + @entry_class = entry_class @metadata = {} - @attributes = { default: entry.default } + @attributes = { default: entry_class.default } end def value(value) @@ -34,6 +36,10 @@ module Gitlab @attributes[:description] end + def inherit + @attributes[:inherit] + end + def inheritable? @attributes[:inherit] end @@ -52,7 +58,7 @@ module Gitlab if @value.nil? Entry::Unspecified.new(fabricate_unspecified) else - fabricate(@entry, @value) + fabricate(entry_class, @value) end end @@ -68,12 +74,12 @@ module Gitlab if default.nil? fabricate(Entry::Undefined) else - fabricate(@entry, default) + fabricate(entry_class, default) end end - def fabricate(entry, value = nil) - entry.new(value, @metadata) do |node| + def fabricate(entry_class, value = nil) + entry_class.new(value, @metadata) do |node| node.key = @attributes[:key] node.parent = @attributes[:parent] node.default = @attributes[:default] 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 |