module Cumuliform::Output
Manages converting the Cumuliform::Template
into a CloudFormation JSON string
Public Instance Methods
to_hash()
click to toggle source
Processes the template and returns a hash representing the CloudFormation template
@return [Hash] Hash representing the CloudFormation template
# 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_json()
click to toggle source
Generates the JSON representation of the template from the Hash representation provided by to_hash
@return [String] JSON representation of the CloudFormation template
# File lib/cumuliform/output.rb, line 33 def to_json JSON.pretty_generate(to_hash) end
Private Instance Methods
generate_item(logical_id, block)
click to toggle source
# File lib/cumuliform/output.rb, line 47 def generate_item(logical_id, block) raise Error::EmptyItem, logical_id if block.nil? item_body = instance_exec(&block) raise Error::EmptyItem, logical_id if item_body.empty? item_body end
generate_section(section)
click to toggle source
# File lib/cumuliform/output.rb, line 39 def generate_section(section) output = {} section.each do |logical_id, block| output[logical_id] = generate_item(logical_id, block) end output end