Class: Lono::Template::Strategy::Dsl::Builder

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Extensions::Loader, Context::Loader, Syntax, Util
Defined in:
lib/lono/template/strategy/dsl/builder/syntax.rb,
lib/lono/template/strategy/dsl/builder.rb,
lib/lono/template/strategy/dsl/builder/fn.rb,
lib/lono/template/strategy/dsl/builder/helpers.rb,
lib/lono/template/strategy/dsl/builder/squeezer.rb,
lib/lono/template/strategy/dsl/builder/stringify.rb

Overview

Built-in helpers for the DSL form

Defined Under Namespace

Modules: Fn, Helpers, Section, Stringify, Syntax Classes: Squeezer

Constant Summary

Constants included from Fn

Fn::FUNCTIONS

Instance Method Summary collapse

Methods included from Common::Helpers

#extract_scripts, #scripts_name, #scripts_s3_path, #setting

Methods included from Syntax::ExtendWith

#extend_with

Methods included from Syntax::ParameterGroup

#parameter_group

Methods included from Section::Methods

#aws_template_format_version, #condition, #description, #mapping, #metadata, #output, #parameter, #resource, #section, #transform

Methods included from Evaluate

#evaluate_template_path, #template_evaluation_error

Methods included from Fn

#conditional_ref, define_methods, #fn, #fn_id, #get_att, #get_azs, included, #join, #ref, #sub

Methods included from Extensions::Loader

#find_extensions_root_path, #load_all_extension_helpers, #load_extension_helpers

Methods included from Context::Loader::LoadFiles

#load_files

Methods included from Util

#ensure_parent_dir

Constructor Details

#initialize(options = {}) ⇒ Builder

Returns a new instance of Builder.



10
11
12
13
14
15
16
# 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

Instance Method Details

#buildObject



18
19
20
21
22
23
24
25
26
# 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

#finalizeObject



34
35
36
37
# 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_extensionsObject

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



29
30
31
32
# 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_yamlObject



39
40
41
42
43
44
# 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_outputObject



46
47
48
49
50
51
52
53
54
55
56
57
# 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