Sha256: 5e2ac9fe13990aa8109d5ca7e1b94f3770824a45fc701714375acda05739050a

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require "render_me_pretty"

class Kubes::Compiler::Strategy
  class Erb < Base
    extend Kubes::Compiler::Dsl::Core::Fields
    include Kubes::Compiler::Dsl::Core::Helpers
    include Kubes::Compiler::Layering
    include Kubes::Compiler::Shared::CustomHelpers
    include Kubes::Compiler::Shared::CustomVariables
    include Kubes::Compiler::Shared::Helpers
    include Kubes::Compiler::Shared::PluginHelpers

    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_plugin_helpers
      load_custom_variables
      load_custom_helpers
    end

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

      yaml = RenderMePretty.result(path, context: self)
      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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kubes-0.7.0 lib/kubes/compiler/strategy/erb.rb