class Lono::Output::Template
Public Class Methods
new(blueprint, template)
click to toggle source
# File lib/lono/output/template.rb, line 5 def initialize(blueprint, template) @blueprint, @template = blueprint, template end
Public Instance Methods
data()
click to toggle source
# 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_parameters()
click to toggle source
# File lib/lono/output/template.rb, line 13 def optional_parameters parameters.reject { |logical_id, p| p["Default"].nil? } end
parameter_groups()
click to toggle source
# 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
parameters()
click to toggle source
# 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_parameters()
click to toggle source
# File lib/lono/output/template.rb, line 9 def required_parameters parameters.select { |logical_id, p| p["Default"].nil? } end
Private Instance Methods
check_template_exists!(template_path)
click to toggle source
Check if the template exists and print friendly error message. Exits if it does not exist.
# File lib/lono/output/template.rb, line 56 def check_template_exists!(template_path) return if File.exist?(template_path) puts "The template #{template_path} does not exist. Are you sure you use the right template name? The template name does not require the extension.".color(:red) exit 1 end
sort_parameter_group(list)
click to toggle source
# File lib/lono/output/template.rb, line 45 def sort_parameter_group(list) list.sort_by do |name| raw_parameters = data["Parameters"] || [] param = raw_parameters[name] optional = !param["Default"].nil? [optional, name].join('-') end end