class Kubes::Compiler::Strategy::Dispatcher

Public Instance Methods

block_form?(path) click to toggle source
# File lib/kubes/compiler/strategy/dispatcher.rb, line 40
def block_form?(path)
  type = extract_type(path)
  type.pluralize == type
end
dispatch() click to toggle source
# File lib/kubes/compiler/strategy/dispatcher.rb, line 3
def dispatch
  result = render(@path) # main
  results = [result].flatten # ensure array
  data = results.map! do |main|
    hash = Kubes.deep_merge!(pre_layer, main)
    Kubes.deep_merge!(hash, post_layer)
  end
  Result.new(@save_file, data)
end
dsl_class(path) click to toggle source

Must be defined here in case coming from Kubes::Compiler::Strategy::Erb#render

# File lib/kubes/compiler/strategy/dispatcher.rb, line 24
def dsl_class(path)
  if block_form?(path)
    Kubes::Compiler::Dsl::Core::Blocks
  else
    syntax_class
  end
end
merge_layers(layers) click to toggle source
# File lib/kubes/compiler/strategy/dispatcher.rb, line 53
def merge_layers(layers)
  layers.inject({}) do |hash, layer|
    data = render(layer)
    hash.deep_merge!(data)
  end
end
post_layer() click to toggle source
# File lib/kubes/compiler/strategy/dispatcher.rb, line 49
def post_layer
  merge_layers(post_layers)
end
pre_layer() click to toggle source
# File lib/kubes/compiler/strategy/dispatcher.rb, line 45
def pre_layer
  merge_layers(pre_layers)
end
render(path) click to toggle source

Render via to Erb or one of the DSL syntax classes or Core/Blocks class

# File lib/kubes/compiler/strategy/dispatcher.rb, line 14
def render(path)
  if path.include?('.rb')
    klass = dsl_class(path) # IE: Kubes::Compiler::Dsl::Syntax::Deployment or Kubes::Compiler::Dsl::Core::Blocks
    klass.new(@options.merge(path: path, data: @data)).run
  else
    Erb.new(@options.merge(data: @data)).render_result(path)
  end
end
syntax_class() click to toggle source
# File lib/kubes/compiler/strategy/dispatcher.rb, line 32
def syntax_class
  klass_name = normalize_kind(@save_file) # IE: @save_file: web/service.yaml
  "Kubes::Compiler::Dsl::Syntax::#{klass_name}".constantize
rescue NameError
  logger.debug "Using default resource for: #{klass_name}"
  Kubes::Compiler::Dsl::Syntax::Resource # default
end