Class: Lono::Output::Template

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/lono/output/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(blueprint, template) ⇒ Template

Returns a new instance of Template.



5
6
7
# File 'lib/lono/output/template.rb', line 5

def initialize(blueprint, template)
  @blueprint, @template = blueprint, template
end

Instance Method Details

#dataObject



37
38
39
40
41
# File 'lib/lono/output/template.rb', line 37

def data
  template_path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
  check_template_exists!(template_path)
  YAML.load(IO.read(template_path))
end

#optional_parametersObject



13
14
15
# File 'lib/lono/output/template.rb', line 13

def optional_parameters
  parameters.reject { |logical_id, p| p["Default"].nil? }
end

#parameter_groupsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/lono/output/template.rb', line 26

def parameter_groups
  interface = data.dig("Metadata", "AWS::CloudFormation::Interface")
  return unless interface
  pgs = interface["ParameterGroups"]
  pgs.inject({}) do |result, pg|
    label = pg["Label"]["default"]
    parameters = sort_parameter_group(pg["Parameters"])
    result.merge(label => parameters)
  end
end

#parametersObject



17
18
19
20
21
22
23
24
# File 'lib/lono/output/template.rb', line 17

def parameters
  list = data["Parameters"] || []
  # Not using sort_parameter_group because structure is different
  list.sort_by do |name, data|
    optional = !data["Default"].nil?
    [optional, name].join('-')
  end.to_h
end

#required_parametersObject



9
10
11
# File 'lib/lono/output/template.rb', line 9

def required_parameters
  parameters.select { |logical_id, p| p["Default"].nil? }
end