Class: Gitlab::Config::Entry::ComposableArray

Inherits:
Node
  • Object
show all
Includes:
Validatable, Utils::StrongMemoize
Defined in:
lib/gitlab/config/entry/composable_array.rb

Overview

Entry that represents a composable array definition

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 Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from Validatable

#errors, included, #validate, #validator

Methods inherited from Node

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

Constructor Details

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

Instance Method Details

#composable_classObject


50
51
52
53
54
# File 'lib/gitlab/config/entry/composable_array.rb', line 50

def composable_class
  strong_memoize(:composable_class) do
    opt(:composable_class)
  end
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
40
# File 'lib/gitlab/config/entry/composable_array.rb', line 19

def compose!(deps = nil)
  super do
    @entries = Array(@entries)

    # TODO: Isolate handling for a hash via: `[@config].flatten` to the `Needs` entry
    # See: https://gitlab.com/gitlab-org/gitlab/-/issues/264376
    [@config].flatten.each_with_index do |value, index|
      raise ArgumentError, 'Missing Composable class' unless composable_class

      composable_class_name = composable_class.name.demodulize.underscore

      @entries << ::Gitlab::Config::Entry::Factory.new(composable_class)
        .value(value)
        .with(key: composable_class_name, parent: self, description: "#{composable_class_name} definition") # rubocop:disable CodeReuse/ActiveRecord
        .create!
    end

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

#descendantsObject


46
47
48
# File 'lib/gitlab/config/entry/composable_array.rb', line 46

def descendants
  @entries
end

#valueObject


42
43
44
# File 'lib/gitlab/config/entry/composable_array.rb', line 42

def value
  @entries.map(&:value)
end