class AwsProvisioner::Template

Attributes

description[R]
format_version[R]
name[RW]
resources[R]

Public Class Methods

new(name=nil, description: nil) click to toggle source
# 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

Public Instance Methods

add(resource) click to toggle source
# File lib/aws_provisioner/template.rb, line 17
def add(resource)
  resources << resource
end
compile(format) click to toggle source
# 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_h() click to toggle source
# File lib/aws_provisioner/template.rb, line 21
def to_h
  {
    "AWSTemplateFormatVersion" => format_version,
    "Description" => description,
    "Resources" => resources_to_h,
  }
end

Private Instance Methods

resources_to_h() click to toggle source
# File lib/aws_provisioner/template.rb, line 40
def resources_to_h
  resources.reduce({}) do |acc, resource|
    acc[resource.name] = resource.to_h

    acc
  end
end