Class: Gitlab::Config::Entry::ComposableHash

Inherits:
Node
  • Object
show all
Includes:
Validatable
Defined in:
lib/gitlab/config/entry/composable_hash.rb

Overview

Entry that represents a composable hash definition Where each hash key can be any value written by the user

Direct Known Subclasses

Gitlab::Ci::Config::Entry::Jobs

Constant Summary

Constants inherited from Node

Node::InvalidError

Instance Attribute Summary

Attributes inherited from Node

#config, #default, #deprecation, #description, #key, #metadata, #parent

Instance Method Summary collapse

Methods included from Validatable

#errors, included, #validate, #validator

Methods inherited from Node

#[], #add_warning, #ancestors, aspects, default, #descendants, #errors, #hash?, #initialize, #inspect, #integer?, #leaf?, #location, #opt, #relevant?, #specified?, #string?, #valid?, #value, #warnings, with_aspect

Constructor Details

This class inherits a constructor from Gitlab::Config::Entry::Node

Instance Method Details

#composable_class(name, config) ⇒ Object


41
42
43
# File 'lib/gitlab/config/entry/composable_hash.rb', line 41

def composable_class(name, config)
  opt(:composable_class)
end

#compose!(deps = nil) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/config/entry/composable_hash.rb', line 19

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)
        .value(config || {})
        .with(key: name, parent: self, description: "#{name} #{entry_class_name} definition") # rubocop:disable CodeReuse/ActiveRecord
        .(name: name)

      @entries[name] = factory.create!
    end

    @entries.each_value do |entry|
      entry.compose!(deps)
    end
  end
end