Class: CloudShaped::TemplateBuilder
- Inherits:
-
Object
- Object
- CloudShaped::TemplateBuilder
- Includes:
- DSL
- Defined in:
- lib/cloud_shaped/template_builder.rb
Overview
A builder for CloudFormation templates.
Constant Summary
Constants included from Interpolation
Interpolation::DEFAULT_DELIMITERS
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#def_mapping(name, mapping = {}) {|mapping| ... } ⇒ Object
Declares a Mappping.
-
#def_output(name, value) ⇒ Object
Declares an Output.
-
#def_parameter(name, options = {}) ⇒ Object
Declares a Parameter.
-
#def_resource(name, type, *args, &block) ⇒ Object
Declares a Resource.
-
#initialize ⇒ TemplateBuilder
constructor
A new instance of TemplateBuilder.
-
#template ⇒ Hash
A CloudFormation template as Ruby data.
Methods included from SnsMethods
Methods included from CoreMethods
#output, #parameter, #ref, #resource, #tag, #tags
Methods included from Interpolation
Methods included from FunctionMethods
Constructor Details
#initialize ⇒ TemplateBuilder
Returns a new instance of TemplateBuilder.
9 10 11 12 13 14 15 |
# File 'lib/cloud_shaped/template_builder.rb', line 9 def initialize @metadata = {} @parameters = {} @mappings = {} @resources = {} @outputs = {} end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
88 89 90 |
# File 'lib/cloud_shaped/template_builder.rb', line 88 def description @description end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
89 90 91 |
# File 'lib/cloud_shaped/template_builder.rb', line 89 def @metadata end |
Instance Method Details
#def_mapping(name, mapping = {}) {|mapping| ... } ⇒ Object
Declares a Mappping.
56 57 58 59 |
# File 'lib/cloud_shaped/template_builder.rb', line 56 def def_mapping(name, mapping = {}) yield mapping if block_given? mappings[name] = mapping end |
#def_output(name, value) ⇒ Object
Declares an Output.
84 85 86 |
# File 'lib/cloud_shaped/template_builder.rb', line 84 def def_output(name, value) outputs[name] = output(value) end |
#def_parameter(name, options = {}) ⇒ Object
Declares a Parameter.
44 45 46 |
# File 'lib/cloud_shaped/template_builder.rb', line 44 def def_parameter(name, = {}) parameters[name] = parameter() end |
#def_resource(name, type, *args, &block) ⇒ Object
Declares a Resource.
67 68 69 70 71 72 73 74 |
# File 'lib/cloud_shaped/template_builder.rb', line 67 def def_resource(name, type, *args, &block) definition = if type.is_a?(Symbol) send(type, *args, &block) else resource(type, *args, &block) end resources[name] = definition if definition end |
#template ⇒ Hash
Returns a CloudFormation template as Ruby data.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cloud_shaped/template_builder.rb', line 19 def template {}.tap do |template| template["AWSTemplateFormatVersion"] = '2010-09-09' template["Description"] = description if description template["Metadata"] = unless .empty? template["Parameters"] = parameters unless parameters.empty? template["Mappings"] = mappings unless mappings.empty? template["Resources"] = resources template["Outputs"] = outputs unless outputs.empty? end end |