debian-mirror-gitlab/lib/gitlab/config/entry/composable_hash.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module Gitlab
module Config
module Entry
##
# Entry that represents a composable hash definition
# Where each hash key can be any value written by the user
#
class ComposableHash < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
# TODO: Refactor `Validatable` code so that validations can apply to a child class
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/263231
validations do
validates :config, type: Hash
end
def compose!(deps = nil)
super do
@config.each do |name, config|
entry_class = composable_class(name, config)
raise ArgumentError, 'Missing Composable class' unless entry_class
entry_class_name = entry_class.name.demodulize.underscore
factory = ::Gitlab::Config::Entry::Factory.new(entry_class)
2022-10-11 01:57:18 +05:30
.value(config.nil? ? {} : config)
2021-01-03 14:25:43 +05:30
.with(key: name, parent: self, description: "#{name} #{entry_class_name} definition") # rubocop:disable CodeReuse/ActiveRecord
2022-10-11 01:57:18 +05:30
.metadata(composable_metadata.merge(name: name))
2021-01-03 14:25:43 +05:30
@entries[name] = factory.create!
end
@entries.each_value do |entry|
entry.compose!(deps)
end
end
end
2022-10-11 01:57:18 +05:30
private
2021-01-03 14:25:43 +05:30
def composable_class(name, config)
opt(:composable_class)
end
2022-10-11 01:57:18 +05:30
def composable_metadata
{}
end
2021-01-03 14:25:43 +05:30
end
end
end
end