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_condition(name, body) ⇒ Object
Declares a Condition.
-
#def_mapping(name, mapping = {}) {|mapping| ... } ⇒ Object
Declares a Mappping.
-
#def_output(name, value) ⇒ Object
Declares an Output.
-
#def_parameter(name, options = {}) {|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
#fn_and, #fn_base64, #fn_equals, #fn_if, #fn_join, #fn_not, #fn_or
Constructor Details
#initialize ⇒ TemplateBuilder
Returns a new instance of TemplateBuilder.
9 10 11 12 13 14 15 16 |
# File 'lib/cloud_shaped/template_builder.rb', line 9 def initialize = {} @parameters = {} @mappings = {} @conditions = {} @resources = {} @outputs = {} end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
103 104 105 |
# File 'lib/cloud_shaped/template_builder.rb', line 103 def description @description end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
104 105 106 |
# File 'lib/cloud_shaped/template_builder.rb', line 104 def end |
Instance Method Details
#def_condition(name, body) ⇒ Object
Declares a Condition.
72 73 74 |
# File 'lib/cloud_shaped/template_builder.rb', line 72 def def_condition(name, body) conditions[name] = body end |
#def_mapping(name, mapping = {}) {|mapping| ... } ⇒ Object
Declares a Mappping.
59 60 61 62 |
# File 'lib/cloud_shaped/template_builder.rb', line 59 def def_mapping(name, mapping = {}) yield mapping if block_given? mappings[name] = mapping end |
#def_output(name, value) ⇒ Object
Declares an Output.
99 100 101 |
# File 'lib/cloud_shaped/template_builder.rb', line 99 def def_output(name, value) outputs[name] = output(value) end |
#def_parameter(name, options = {}) {|options| ... } ⇒ Object
Declares a Parameter.
46 47 48 49 |
# File 'lib/cloud_shaped/template_builder.rb', line 46 def def_parameter(name, = {}) yield if block_given? parameters[name] = parameter() end |
#def_resource(name, type, *args, &block) ⇒ Object
Declares a Resource.
82 83 84 85 86 87 88 89 |
# File 'lib/cloud_shaped/template_builder.rb', line 82 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.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cloud_shaped/template_builder.rb', line 20 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["Conditions"] = conditions unless conditions.empty? template["Resources"] = resources template["Outputs"] = outputs unless outputs.empty? end end |