Class: AwsProvisioner::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_provisioner/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, description: nil) ⇒ Template

Returns a new instance of Template.



10
11
12
13
14
15
# File 'lib/aws_provisioner/template.rb', line 10

def initialize(name=nil, description: nil)
  @format_version = "2010-09-09"
  @description = description
  @resources = []
  @name = name
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/aws_provisioner/template.rb', line 8

def description
  @description
end

#format_versionObject (readonly)

Returns the value of attribute format_version.



8
9
10
# File 'lib/aws_provisioner/template.rb', line 8

def format_version
  @format_version
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/aws_provisioner/template.rb', line 7

def name
  @name
end

#resourcesObject (readonly)

Returns the value of attribute resources.



8
9
10
# File 'lib/aws_provisioner/template.rb', line 8

def resources
  @resources
end

Instance Method Details

#add(resource) ⇒ Object



17
18
19
# File 'lib/aws_provisioner/template.rb', line 17

def add(resource)
  resources << resource
end

#compile(format) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/aws_provisioner/template.rb', line 29

def compile(format)
  case format
  when :json
    JSON.pretty_generate(to_h)
  when :yaml
    YAML.dump(to_h)
  end
end

#to_hObject



21
22
23
24
25
26
27
# File 'lib/aws_provisioner/template.rb', line 21

def to_h
  {
    "AWSTemplateFormatVersion" => format_version,
    "Description" => description,
    "Resources" => resources_to_h,
  }
end