Class: Aws::Cfn::DeCompiler::Base

Inherits:
Compiler::Base
  • Object
show all
Includes:
Options
Defined in:
lib/aws/cfn/decompiler/base.rb

Direct Known Subclasses

Main

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Options

#parse_options, #set_config_options

Instance Attribute Details

#templateObject

Returns the value of attribute template.



12
13
14
# File 'lib/aws/cfn/decompiler/base.rb', line 12

def template
  @template
end

Instance Method Details

#save_dsl(output_dir, decompiled = @items) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/aws/cfn/decompiler/base.rb', line 17

def save_dsl(output_dir, decompiled=@items)

  specification = {}
  format = @config[:format] rescue 'yaml'
  ruby   = (not format.match(%r'^ruby|rb$').nil?)
  if ruby
    pprint_cfn_template simplify(decompiled)
  end
  decompiled.each do |section, section_items|
    case section
      when /Mappings|Parameters|Resources|Outputs/
        specification[section] = []
        section_items.each do |name,value|
          unless ruby
            dir  = File.join(output_dir,section.to_s)
            unless File.directory?(dir)
              Dir.mkdir(dir)
            end
            file = "#{name}.#{format}"
            hash = {  name => value }

            save_section(dir, file, format, section, hash)
          end
          specification[section] << name
        end
      when /AWSTemplateFormatVersion|Description/
        specification[section] = section_items
      else
        abort! "Unsupported section '#{section}' in template"
    end
  end

  # Save specification
  unless @config[:specification].nil?
    dir = File.dirname(@config[:specification])
    dir = output_dir unless dir
    save_section(dir, File.basename(@config[:specification]), format, '', specification, '', "specification")
  end

end