Class: Lono::Output::Template
- Inherits:
-
Object
- Object
- Lono::Output::Template
- Extended by:
- Memoist
- Defined in:
- lib/lono/output/template.rb
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(blueprint, template) ⇒ Template
constructor
A new instance of Template.
- #optional_parameters ⇒ Object
- #parameter_groups ⇒ Object
- #parameters ⇒ Object
- #required_parameters ⇒ Object
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
#data ⇒ Object
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_parameters ⇒ Object
13 14 15 |
# File 'lib/lono/output/template.rb', line 13 def optional_parameters parameters.reject { |logical_id, p| p["Default"].nil? } end |
#parameter_groups ⇒ Object
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 |
#parameters ⇒ Object
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_parameters ⇒ Object
9 10 11 |
# File 'lib/lono/output/template.rb', line 9 def required_parameters parameters.select { |logical_id, p| p["Default"].nil? } end |