Class: CloudFormer::Template
- Inherits:
-
Object
- Object
- CloudFormer::Template
- Defined in:
- lib/cloud_former/template.rb
Instance Method Summary collapse
- #add_condition(condition) ⇒ Object
- #add_mapping(name, hash) ⇒ Object
- #add_output(key, value) ⇒ Object
- #add_parameter(parameter) ⇒ Object
- #add_resource(resource) ⇒ Object
- #condition(name) ⇒ Object
- #dump_json ⇒ Object
-
#initialize ⇒ Template
constructor
A new instance of Template.
- #parameter(name) ⇒ Object
- #resource(name) ⇒ Object
Constructor Details
#initialize ⇒ Template
Returns a new instance of Template.
4 5 6 7 8 9 10 |
# File 'lib/cloud_former/template.rb', line 4 def initialize @resources = [] @parameters = [] @outputs = [] @conditions = [] @mappings = {} end |
Instance Method Details
#add_condition(condition) ⇒ Object
32 33 34 |
# File 'lib/cloud_former/template.rb', line 32 def add_condition(condition) @conditions << condition end |
#add_mapping(name, hash) ⇒ Object
40 41 42 |
# File 'lib/cloud_former/template.rb', line 40 def add_mapping(name, hash) @mappings[name] = hash end |
#add_output(key, value) ⇒ Object
28 29 30 |
# File 'lib/cloud_former/template.rb', line 28 def add_output(key, value) @outputs << [key, value] end |
#add_parameter(parameter) ⇒ Object
12 13 14 |
# File 'lib/cloud_former/template.rb', line 12 def add_parameter(parameter) @parameters << parameter end |
#add_resource(resource) ⇒ Object
20 21 22 |
# File 'lib/cloud_former/template.rb', line 20 def add_resource(resource) @resources << resource end |
#condition(name) ⇒ Object
36 37 38 |
# File 'lib/cloud_former/template.rb', line 36 def condition(name) @conditions.find { |c| c.get_name == name } end |
#dump_json ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cloud_former/template.rb', line 44 def dump_json res = { 'AWSTemplateFormatVersion' => '2010-09-09' } if @parameters.any? parameter_res = {} @parameters.each do |param| parameter_res[param.get_name] = param.dump_json end res['Parameters'] = parameter_res end if @conditions.any? condition_res = {} @conditions.each do |condition| condition_res[condition.get_name] = condition.dump_json end res['Conditions'] = condition_res end if @mappings.any? res['Mappings'] = @mappings end if @resources.any? resource_res = {} @resources.each do |resource| resource.resource_tree.flatten.each do |r| resource_res[r.get_name] = r.dump_json end end res['Resources'] = resource_res end if @outputs.any? output_res = {} @outputs.each do |output| if output[1].is_a?(Resource) || output[1].is_a?(Parameter) output_res[output[0]] = { 'Value' => { 'Ref' => output[1].get_name } } elsif output[1].is_a?(Function) output_res[output[0]] = { 'Value' => output[1].dump_json } else output_res[output[0]] = { 'Value' => output[1] } end end res['Outputs'] = output_res end res end |
#parameter(name) ⇒ Object
16 17 18 |
# File 'lib/cloud_former/template.rb', line 16 def parameter(name) @parameters.find { |p| p.get_name == name } end |
#resource(name) ⇒ Object
24 25 26 |
# File 'lib/cloud_former/template.rb', line 24 def resource(name) @resources.find { |r| r.get_name == name } end |