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.



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

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

Class Attribute Details

.label_namespaceObject



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

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

#kindObject (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#label_namespaceObject (readonly)

Returns the value of attribute label_namespace.



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

def label_namespace
  @label_namespace
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



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

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

.initializersObject



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

def initializers
  @initializers ||= []
end

.metatron_template_class?Boolean

Returns:

  • (Boolean)


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

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



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

def nearest_metatron_ancestor
  return self if metatron_template_class?

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

Instance Method Details

#base_labelsObject



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

def base_labels = { "#{label_namespace}/name": name }