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



32
33
34
35
36
# File 'lib/lono/output/template.rb', line 32

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



21
22
23
24
25
26
27
28
29
30
# File 'lib/lono/output/template.rb', line 21

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

#parametersObject



17
18
19
# File 'lib/lono/output/template.rb', line 17

def parameters
  data["Parameters"] || []
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