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

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
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 Helpers::TagsHelper

#dimensions, #tag_list, #tags

Methods included from Helpers::S3Helper

#file_s3_key, #s3_bucket

Methods included from Helpers::LookupHelper

#lookup_output

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods included from Helpers::FileHelper

#content, #render_file, #render_path, #user_data, #user_data_script

Methods included from Helpers::CoreHelper

#setting, #stack_name

Methods included from Section::Extensions

#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 Util

#ensure_parent_dir

Constructor Details

#initialize(path, blueprint, options = {}) ⇒ Builder

Returns a new instance of Builder.



9
10
11
12
13
14
# File 'lib/lono/template/strategy/dsl/builder.rb', line 9

def initialize(path, blueprint, options={})
  @path, @blueprint, @options = path, blueprint, options
  @template = @path.sub("#{Lono.config.templates_path}/",'').sub(/\.rb$/,'')
  @parameters = [] # registry
  @cfn = {}
end

Instance Method Details

#buildObject



16
17
18
19
20
21
22
23
# File 'lib/lono/template/strategy/dsl/builder.rb', line 16

def build
  load_context
  evaluate_template_path(@path) # modifies @cfn
  finalize
  to_yaml
  write_output
  @cfn
end

#finalizeObject



25
26
27
28
# File 'lib/lono/template/strategy/dsl/builder.rb', line 25

def finalize
  o = @options.merge(parameters: @parameters)
  @cfn = Finalizer.new(@cfn, o).run
end

#load_contextObject

Not using Lono::Template::Context because that works differently. That is used to load a context object that is passed to RenderMePretty’s context. So that we can load context for params files and erb templates.

In this case builder is actually the dsl context. We want to load variables and helpers into this builder context directly. This loads additional context. It looks very similar to Lono::Template::Context



57
58
59
60
# File 'lib/lono/template/strategy/dsl/builder.rb', line 57

def load_context
  load_variables
  load_project_helpers
end

#to_yamlObject



30
31
32
33
34
35
# File 'lib/lono/template/strategy/dsl/builder.rb', line 30

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



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lono/template/strategy/dsl/builder.rb', line 37

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