Class: Kubes::Compiler::Strategy::Erb

Inherits:
Base
  • Object
show all
Extended by:
Dsl::Core::Fields
Includes:
Dsl::Core::Helpers, Layering, Kubes::Compiler::Shared::RuntimeHelpers
Defined in:
lib/kubes/compiler/strategy/erb/comment.rb,
lib/kubes/compiler/strategy/erb.rb,
lib/kubes/compiler/strategy/erb/yaml_error.rb

Overview

Processes the ERB files and looks for comments like

#ERB if @testvar
- "some yaml"
#ERB end

Defined Under Namespace

Classes: Comment, YamlError

Instance Method Summary collapse

Methods included from Kubes::Compiler::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 Kubes::Compiler::Shared::Helpers::SecretHelper

#decode64, #encode64, #generic_secret_data, #parse_env_like_line

Methods included from Kubes::Compiler::Shared::Helpers::ExtraHelper

#extra, #with_extra

Methods included from Kubes::Compiler::Shared::Helpers::DockerHelper

#built_image, #built_image_helper, #docker_image

Methods included from Kubes::Compiler::Shared::Helpers::ConfigMapHelper

#config_map_files

Methods included from Layering

#add_exts, #post_layers, #pre_layers

Methods included from Logging

#logger

Methods included from Util::SaveFile

#save_file

Methods included from Util::Normalize

#extract_type, #normalize_kind

Constructor Details

#initialize(options = {}) ⇒ Erb

Returns a new instance of Erb.



10
11
12
13
14
15
# File 'lib/kubes/compiler/strategy/erb.rb', line 10

def initialize(options={})
  super
  # For ERB scope is in this same Strategy::Erb class
  # For DSL scope is within the each for the Resource classes. IE: kubes/compile/dsl/core/base.rb
  load_runtime_helpers
end

Instance Method Details

#render_result(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kubes/compiler/strategy/erb.rb', line 17

def render_result(path)
  return unless File.exist?(path)

  comment = Comment.new(path)
  path = comment.process if comment.process?
  yaml = RenderMePretty.result(path, context: self)
  comment.clean if comment.process?

  result = yaml_load(path, yaml)
  # in case of blank yaml doc a Boolean false is returned. else Hash or Array is returned
  %w[Array Hash].include?(result.class.to_s) ? result : {}
end

#yaml_load(path, yaml) ⇒ Object



30
31
32
33
34
35
# File 'lib/kubes/compiler/strategy/erb.rb', line 30

def yaml_load(path, yaml)
  YAML.load(yaml)
rescue Psych::SyntaxError
  YamlError.new(path, yaml).show
  exit 1
end