Module: Cumuliform::Output

Included in:
Template
Defined in:
lib/cumuliform/output.rb

Overview

Manages converting the Cumuliform::Template into a CloudFormation JSON string

Instance Method Summary collapse

Instance Method Details

#to_hashHash

Processes the template and returns a hash representing the CloudFormation template

Returns:

  • (Hash)

    Hash representing the CloudFormation template

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cumuliform/output.rb', line 14

def to_hash
  output = {}
  TOP_LEVEL.each do |item_name|
    value = get_top_level_value(item_name)
    output[item_name] = value unless value.nil?
  end
  SECTION_NAMES.each do |section_name|
    section = get_section(section_name)
    output[section_name] = generate_section(section) unless section.empty?
  end

  raise Error::NoResourcesDefined unless output.has_key?("Resources")
  output
end

#to_jsonString

Generates the JSON representation of the template from the Hash representation provided by #to_hash

Returns:

  • (String)

    JSON representation of the CloudFormation template



33
34
35
# File 'lib/cumuliform/output.rb', line 33

def to_json
  JSON.pretty_generate(to_hash)
end