Class: Kubes::Compiler::Dsl::Core::Blocks

Inherits:
Base
  • Object
show all
Defined in:
lib/kubes/compiler/dsl/core/blocks.rb

Constant Summary collapse

@@syntax_instances =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Fields

#field, #fields

Methods included from Shared::RuntimeHelpers

#base_class_for_helper, #load_custom_helpers, #load_custom_variables, #load_plugin_helpers, #load_runtime_helpers, #show_variable_layer_path

Methods included from Util::Pretty

#pretty_path

Methods included from Shared::Helpers::SecretHelper

#decode64, #encode64, #generic_secret_data, #parse_env_like_line

Methods included from Shared::Helpers::ExtraHelper

#extra, #with_extra

Methods included from Shared::Helpers::DockerHelper

#built_image, #built_image_helper, #docker_image

Methods included from Shared::Helpers::ConfigMapHelper

#config_map_files

Methods included from Helpers

#dockerfile_port

Constructor Details

This class inherits a constructor from Kubes::Compiler::Dsl::Core::Base

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



3
4
5
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 3

def results
  @results
end

Class Method Details

.block_method(meth) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 39

def block_method(meth)
  meth = meth.to_s
  define_method meth do |name, &block|
    syntax = syntax_instance(meth, name)
    syntax.instance_eval(&block) if block
    lookup = lookup_key(meth, name)
    @results[lookup] = syntax.result
  end
end

.discovered_methodsObject



31
32
33
34
35
36
37
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 31

def discovered_methods
  syntax = File.expand_path("../syntax", __dir__)
  expr = "#{syntax}/*.rb"
  Dir.glob(expr).map do |path|
    File.basename(path).sub('.rb','')
  end
end

.syntax_instancesObject



50
51
52
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 50

def syntax_instances
  @@syntax_instances
end

Instance Method Details

#lookup_key(meth, name) ⇒ Object



26
27
28
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 26

def lookup_key(meth, name)
  [meth, name].join('-')
end

#resultObject



11
12
13
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 11

def result
  @results.values # Array
end

#runObject



4
5
6
7
8
9
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 4

def run
  @results = {} # Hash key is the name of resource, using it so we can keep a map to handle layering
  @block_form = true # pluralizes the layer names
  super # handles layering and evaluating the main DSL file
  result # Array
end

#syntax_instance(meth, name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/kubes/compiler/dsl/core/blocks.rb', line 15

def syntax_instance(meth, name)
  lookup = lookup_key(meth, name)
  klass = "Kubes::Compiler::Dsl::Syntax::#{meth.camelize}".constantize
  syntax = self.class.syntax_instances[lookup]
  return syntax if syntax

  syntax = klass.new(@options.merge(name: name))
  syntax.kind_from_block = meth.camelize
  self.class.syntax_instances[lookup] = syntax
end