Class: Metatron::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/metatron/template.rb

Overview

Base class for templating Kubernetes resources

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Template

Returns a new instance of Template.

[View source]

40
41
42
43
44
45
46
# File 'lib/metatron/template.rb', line 40

def initialize(name)
  @name = name
  @api_version = "v1"
  @kind = find_kind
  @additional_labels = {}
  run_initializers
end

Class Attribute Details

.label_namespaceObject


13
14
15
# File 'lib/metatron/template.rb', line 13

def label_namespace
  @label_namespace ||= "metatron.therubyist.org"
end

Instance Attribute Details

#additional_labelsObject

Returns the value of attribute additional_labels.


6
7
8
# File 'lib/metatron/template.rb', line 6

def additional_labels
  @additional_labels
end

#api_versionObject Also known as: apiVersion

Returns the value of attribute api_version.


6
7
8
# File 'lib/metatron/template.rb', line 6

def api_version
  @api_version
end

#base_labelsObject


50
51
52
# File 'lib/metatron/template.rb', line 50

def base_labels
  @base_labels || { "#{label_namespace}/name": name }
end

#kindObject (readonly)

Returns the value of attribute kind.


7
8
9
# File 'lib/metatron/template.rb', line 7

def kind
  @kind
end

#nameObject

Returns the value of attribute name.


6
7
8
# File 'lib/metatron/template.rb', line 6

def name
  @name
end

Class Method Details

.initializer(*args) ⇒ Object

[View source]

17
18
19
20
# File 'lib/metatron/template.rb', line 17

def initializer(*args)
  @initializers ||= []
  @initializers += args
end

.initializersObject

[View source]

22
23
24
# File 'lib/metatron/template.rb', line 22

def initializers
  @initializers ||= []
end

.metatron_template_class?Boolean

Returns:

  • (Boolean)
[View source]

32
33
34
35
36
37
# File 'lib/metatron/template.rb', line 32

def metatron_template_class?
  return true if name == "Metatron::Template"
  return false if name.start_with?("Metatron::Templates::Concerns")

  name.start_with?("Metatron::Templates::")
end

.nearest_metatron_ancestorObject

[View source]

26
27
28
29
30
# File 'lib/metatron/template.rb', line 26

def nearest_metatron_ancestor
  return self if metatron_template_class?

  ancestors.find { _1.respond_to?(:metatron_template_class?) && _1.metatron_template_class? }
end