class Lono::Template::Strategy::Dsl::Builder

Built-in helpers for the DSL form

Encapsulates syntax methods so they can be included in both the Builder and Context scope

Public Class Methods

new(options={}) click to toggle source
# File lib/lono/template/strategy/dsl/builder.rb, line 10
def initialize(options={})
  @options = options
  @stack, @blueprint, @template, @param = Lono::Conventions.new(options).values
  @template_path = "#{Lono.config.templates_path}/#{@template}.rb"
  @parameters = [] # registry
  @cfn = {}
end

Public Instance Methods

build() click to toggle source
# File lib/lono/template/strategy/dsl/builder.rb, line 18
def build
  load_extensions # load_extensions before project helpers
  load_context # variables and project helpers
  evaluate_template_path(@template_path) # modifies @cfn
  finalize
  to_yaml
  write_output
  @cfn
end
finalize() click to toggle source
# File lib/lono/template/strategy/dsl/builder.rb, line 34
def finalize
  o = @options.merge(parameters: @parameters)
  @cfn = Finalizer.new(@cfn, o).run
end
load_extensions() click to toggle source

load_extensions and evaluate extend_with methods earlier than load_context so project helpers can override extensions

# File lib/lono/template/strategy/dsl/builder.rb, line 29
def load_extensions # evaluates extend_with
  Lono::Extensions::Preparer.new(@options).run
  load_all_extension_helpers # after Extensions::Preparer#run
end
to_yaml() click to toggle source
# File lib/lono/template/strategy/dsl/builder.rb, line 39
def to_yaml
  # https://stackoverflow.com/questions/24508364/how-to-emit-yaml-in-ruby-expanding-aliases
  # Trick to prevent YAML from emitting aliases
  @cfn = YAML.load(@cfn.to_json)
  @results = YAML.dump(@cfn)
end
write_output() click to toggle source
# File lib/lono/template/strategy/dsl/builder.rb, line 46
def write_output
  path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
  ensure_parent_dir(path)
  IO.write(path, @results)

  Lono::Yamler::Validator.new(path).validate!

  unless @options[:quiet]
    pretty_path = path.sub("#{Lono.root}/",'')
    puts "  #{pretty_path}"
  end
end