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.



17
18
19
20
21
22
23
24
# File 'lib/metatron/template.rb', line 17

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



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

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

.initializersObject



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

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

.metatron_template_class?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/metatron/template.rb', line 43

def self.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



37
38
39
40
41
# File 'lib/metatron/template.rb', line 37

def self.nearest_metatron_ancestor
  return self if metatron_template_class?

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