Class: CloudFormation

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

Constant Summary collapse

ELEMENTS =
[
  :parameters,
  :resources,
  :conditions,
  :outputs,
  :mappings,
  :rules,
  :metadata,
  :description,
  :aws_template_format_version
]

Instance Method Summary collapse

Constructor Details

#initialize(cfn_string) ⇒ CloudFormation

Returns a new instance of CloudFormation.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cloudformation.rb', line 19

def initialize(cfn_string)
  cfn_hash = Psych.safe_load(cfn_string)
  ELEMENTS.each do |e|
    key  = e.to_s.camel_case
    if key =~ /^Aws/
      key = key.sub(/^Aws/, "AWS")
    end

    if cfn_hash[key]
      attr = parse_element(e, cfn_hash[key])
      instance_variable_set("@" + e.to_s, attr)
    end
  end
rescue Psych::DisallowedClass => error
  raise YamlValueTypeError.new "Unsupported YAML value type found: only scalar values supported. #{error.message}"
rescue Psych::Exception => error
  raise YamlSyntaxError.new "Syntax error in template. #{error.message}"
end