Class: Moonshot::StackTemplate
- Inherits:
-
Object
- Object
- Moonshot::StackTemplate
- Defined in:
- lib/moonshot/stack_template.rb
Overview
A StackTemplate loads the JSON template from disk and stores information about it.
Defined Under Namespace
Classes: Parameter
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(filename, log:) ⇒ StackTemplate
constructor
A new instance of StackTemplate.
- #parameters ⇒ Object
-
#resource_names ⇒ Object
Return a list of defined resource names in the template.
Constructor Details
#initialize(filename, log:) ⇒ StackTemplate
Returns a new instance of StackTemplate.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/moonshot/stack_template.rb', line 15 def initialize(filename, log:) @log = log unless File.exist?(filename) @log.error("Could not find CloudFormation template at #{filename}") raise end # The maximum TemplateBody length is 51,200 bytes, so we remove # formatting white space. @body = JSON.parse(File.read(filename)).to_json end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/moonshot/stack_template.rb', line 13 def body @body end |
Instance Method Details
#parameters ⇒ Object
28 29 30 31 32 |
# File 'lib/moonshot/stack_template.rb', line 28 def parameters JSON.parse(@body).fetch('Parameters', {}).map do |k, v| Parameter.new(k, v['Default']) end end |
#resource_names ⇒ Object
Return a list of defined resource names in the template.
35 36 37 |
# File 'lib/moonshot/stack_template.rb', line 35 def resource_names JSON.parse(@body).fetch('Resources', {}).keys end |