Module: Jets::Cfn::TemplateBuilders::Interface
- Included in:
- ApiGatewayBuilder, ApiGatewayDeploymentBuilder, BaseChildBuilder, ParentBuilder
- Defined in:
- lib/jets/cfn/template_builders/interface.rb
Instance Method Summary collapse
- #add_output(name, options = {}) ⇒ Object
- #add_parameter(name, options = {}) ⇒ Object
-
#add_resource(logical_id, type, options) ⇒ Object
Example:.
- #build ⇒ Object
-
#post_process_template(text) ⇒ Object
post process the text so that “!Ref IamRole” => !Ref IamRole We strip the surrounding quotes.
- #template ⇒ Object
- #text ⇒ Object
- #write ⇒ Object
Instance Method Details
#add_output(name, options = {}) ⇒ Object
87 88 89 90 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 87 def add_output(name, ={}) @template[:Outputs] ||= {} @template[:Outputs][name.camelize] = end |
#add_parameter(name, options = {}) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 80 def add_parameter(name, ={}) defaults = { Type: "String" } = defaults.merge() @template[:Parameters] ||= {} @template[:Parameters][name.camelize] = end |
#add_resource(logical_id, type, options) ⇒ Object
Example:
Simple options with properties only: add_resource(“MyId”, “AWS::CloudFormationStack”,
TemplateURL: "template_url",
Parameters: {},
)
More complicated options: add_resource(“MyId”, “AWS::ApiGateway::RestApi”,
Properties: {
Name: "my-api"
},
DependsOn: ["AnotherResource"]
)
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 65 def add_resource(logical_id, type, ) base = { Type: type } = if .include?(:Properties) base.merge() else { Type: type, Properties: # options are properties } end @template[:Resources][logical_id] = end |
#build ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 7 def build # Do not bother building # or writing the template unless there are functions defined return if @app_klass && !@app_klass.build? compose # must be implemented by subclass write end |
#post_process_template(text) ⇒ Object
post process the text so that “!Ref IamRole” => !Ref IamRole We strip the surrounding quotes
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 35 def post_process_template(text) results = text.split("\n").map do |line| if line.include?(': "!') # IE: IamRole: "!Ref IamRole", # IamRole: "!Ref IamRole" => IamRole: !Ref IamRole line.sub(/: "(.*)"/, ': \1') else line end end results.join("\n") + "\n" end |
#template ⇒ Object
21 22 23 24 25 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 21 def template # need the to_hash or the YAML dump has # !ruby/hash:ActiveSupport::HashWithIndifferentAccess @template.to_hash end |
#text ⇒ Object
27 28 29 30 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 27 def text text = YAML.dump(template) post_process_template(text) end |
#write ⇒ Object
16 17 18 19 |
# File 'lib/jets/cfn/template_builders/interface.rb', line 16 def write FileUtils.mkdir_p(File.dirname(template_path)) IO.write(template_path, text) end |