Class: Gitlab::Config::Entry::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/config/entry/node.rb

Overview

Base abstract class for each configuration entry node.

Direct Known Subclasses

Gitlab::Ci::Config::Entry::Artifacts, Gitlab::Ci::Config::Entry::Bridge, Gitlab::Ci::Config::Entry::Cache, Gitlab::Ci::Config::Entry::Commands, Gitlab::Ci::Config::Entry::Coverage, Gitlab::Ci::Config::Entry::Default, Gitlab::Ci::Config::Entry::Environment, Gitlab::Ci::Config::Entry::Files, Gitlab::Ci::Config::Entry::Hidden, Gitlab::Ci::Config::Entry::Image, Gitlab::Ci::Config::Entry::Include, Gitlab::Ci::Config::Entry::Includes, Gitlab::Ci::Config::Entry::Inherit, Gitlab::Ci::Config::Entry::Inherit::Default::ArrayStrategy, Gitlab::Ci::Config::Entry::Inherit::Default::UnknownStrategy, Gitlab::Ci::Config::Entry::Inherit::Variables::ArrayStrategy, Gitlab::Ci::Config::Entry::Inherit::Variables::UnknownStrategy, Gitlab::Ci::Config::Entry::Job, Gitlab::Ci::Config::Entry::Jobs, Gitlab::Ci::Config::Entry::Key::ComplexKey, Gitlab::Ci::Config::Entry::Key::SimpleKey, Gitlab::Ci::Config::Entry::Key::UnknownStrategy, Gitlab::Ci::Config::Entry::Kubernetes, Gitlab::Ci::Config::Entry::Need::JobHash, Gitlab::Ci::Config::Entry::Need::JobString, Gitlab::Ci::Config::Entry::Need::UnknownStrategy, Gitlab::Ci::Config::Entry::Needs, Gitlab::Ci::Config::Entry::Paths, Gitlab::Ci::Config::Entry::Policy::ComplexPolicy, Gitlab::Ci::Config::Entry::Policy::RefsPolicy, Gitlab::Ci::Config::Entry::Policy::UnknownStrategy, Gitlab::Ci::Config::Entry::Port, Gitlab::Ci::Config::Entry::Ports, Gitlab::Ci::Config::Entry::Prefix, Gitlab::Ci::Config::Entry::Product::Matrix, Gitlab::Ci::Config::Entry::Product::Parallel::MatrixBuilds, Gitlab::Ci::Config::Entry::Product::Parallel::ParallelBuilds, Gitlab::Ci::Config::Entry::Product::Parallel::UnknownStrategy, Gitlab::Ci::Config::Entry::Product::Variables, Gitlab::Ci::Config::Entry::Release, Gitlab::Ci::Config::Entry::Release::Assets, Gitlab::Ci::Config::Entry::Release::Assets::Link, Gitlab::Ci::Config::Entry::Release::Assets::Links, Gitlab::Ci::Config::Entry::Reports, Gitlab::Ci::Config::Entry::Retry::FullRetry, Gitlab::Ci::Config::Entry::Retry::SimpleRetry, Gitlab::Ci::Config::Entry::Retry::UnknownStrategy, Gitlab::Ci::Config::Entry::Root, Gitlab::Ci::Config::Entry::Rules, Gitlab::Ci::Config::Entry::Rules::Rule, Gitlab::Ci::Config::Entry::Script, Gitlab::Ci::Config::Entry::Service, Gitlab::Ci::Config::Entry::Services, Gitlab::Ci::Config::Entry::Stage, Gitlab::Ci::Config::Entry::Stages, Gitlab::Ci::Config::Entry::Timeout, Gitlab::Ci::Config::Entry::Trigger::ComplexTrigger::CrossProjectTrigger, Gitlab::Ci::Config::Entry::Trigger::ComplexTrigger::SameProjectTrigger, Gitlab::Ci::Config::Entry::Trigger::ComplexTrigger::UnknownStrategy, Gitlab::Ci::Config::Entry::Trigger::SimpleTrigger, Gitlab::Ci::Config::Entry::Trigger::UnknownStrategy, Gitlab::Ci::Config::Entry::Variables, Gitlab::Ci::Config::Entry::Workflow, ArrayOfStrings, Boolean, Undefined, WebIde::Config::Entry::Global, WebIde::Config::Entry::Terminal

Constant Summary collapse

InvalidError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, **metadata) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/config/entry/node.rb', line 15

def initialize(config, **)
  @config = config
  @metadata = 
  @entries = {}
  @warnings = []

  yield(self) if block_given?

  self.class.aspects.to_a.each do |aspect|
    instance_exec(&aspect)
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


12
13
14
# File 'lib/gitlab/config/entry/node.rb', line 12

def config
  @config
end

#defaultObject

Returns the value of attribute default


13
14
15
# File 'lib/gitlab/config/entry/node.rb', line 13

def default
  @default
end

#descriptionObject

Returns the value of attribute description


13
14
15
# File 'lib/gitlab/config/entry/node.rb', line 13

def description
  @description
end

#keyObject

Returns the value of attribute key


13
14
15
# File 'lib/gitlab/config/entry/node.rb', line 13

def key
  @key
end

#metadataObject (readonly)

Returns the value of attribute metadata


12
13
14
# File 'lib/gitlab/config/entry/node.rb', line 12

def 
  @metadata
end

#parentObject

Returns the value of attribute parent


13
14
15
# File 'lib/gitlab/config/entry/node.rb', line 13

def parent
  @parent
end

Class Method Details

.aspectsObject


120
121
122
# File 'lib/gitlab/config/entry/node.rb', line 120

def self.aspects
  @aspects ||= []
end

.defaultObject


117
118
# File 'lib/gitlab/config/entry/node.rb', line 117

def self.default(**)
end

.with_aspect(blk) ⇒ Object


124
125
126
# File 'lib/gitlab/config/entry/node.rb', line 124

def self.with_aspect(blk)
  self.aspects.append(blk)
end

Instance Method Details

#[](key) ⇒ Object


28
29
30
# File 'lib/gitlab/config/entry/node.rb', line 28

def [](key)
  @entries[key] || Entry::Undefined.new
end

#add_warning(message) ⇒ Object


68
69
70
# File 'lib/gitlab/config/entry/node.rb', line 68

def add_warning(message)
  @warnings << "#{location} #{message}"
end

#ancestorsObject


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

def ancestors
  @parent ? @parent.ancestors + [@parent] : []
end

#compose!(deps = nil) ⇒ Object


32
33
34
35
36
# File 'lib/gitlab/config/entry/node.rb', line 32

def compose!(deps = nil)
  return unless valid?

  yield if block_given?
end

#descendantsObject


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

def descendants
  @entries.values
end

#errorsObject


60
61
62
# File 'lib/gitlab/config/entry/node.rb', line 60

def errors
  []
end

#hash?Boolean

Returns:


105
106
107
# File 'lib/gitlab/config/entry/node.rb', line 105

def hash?
  @config.is_a?(Hash)
end

#inspectObject


99
100
101
102
103
# File 'lib/gitlab/config/entry/node.rb', line 99

def inspect
  val = leaf? ? config : descendants
  unspecified = specified? ? '' : '(unspecified) '
  "#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>"
end

#integer?Boolean

Returns:


113
114
115
# File 'lib/gitlab/config/entry/node.rb', line 113

def integer?
  @config.is_a?(Integer)
end

#leaf?Boolean

Returns:


38
39
40
# File 'lib/gitlab/config/entry/node.rb', line 38

def leaf?
  @entries.none?
end

#locationObject


92
93
94
95
96
97
# File 'lib/gitlab/config/entry/node.rb', line 92

def location
  name = @key.presence || self.class.name.to_s.demodulize
                              .underscore.humanize.downcase

  ancestors.map(&:key).append(name).compact.join(':')
end

#opt(key) ⇒ Object


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

def opt(key)
  opt = [key]
  opt = @parent.opt(key) if opt.nil? && @parent
  opt
end

#relevant?Boolean

Returns:


88
89
90
# File 'lib/gitlab/config/entry/node.rb', line 88

def relevant?
  true
end

#specified?Boolean

Returns:


84
85
86
# File 'lib/gitlab/config/entry/node.rb', line 84

def specified?
  true
end

#string?Boolean

Returns:


109
110
111
# File 'lib/gitlab/config/entry/node.rb', line 109

def string?
  @config.is_a?(String)
end

#valid?Boolean

Returns:


56
57
58
# File 'lib/gitlab/config/entry/node.rb', line 56

def valid?
  errors.none?
end

#valueObject


72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gitlab/config/entry/node.rb', line 72

def value
  if leaf?
    @config
  else
    meaningful = @entries.select do |_key, value|
      value.specified? && value.relevant?
    end

    meaningful.transform_values { |entry| entry.value }
  end
end

#warningsObject


64
65
66
# File 'lib/gitlab/config/entry/node.rb', line 64

def warnings
  @warnings + descendants.flat_map(&:warnings)
end