Class: Aws::Cfn::Dsl::Base

Inherits:
Object show all
Includes:
DSL, Maintainer, Options, Output, PrettyPrint, Simplify, DLDInternet::Mixlib::Logging
Defined in:
lib/aws/cfn/dsl/base.rb

Direct Known Subclasses

Main

Instance Attribute Summary collapse

Attributes included from Options

#config, #opts

Instance Method Summary collapse

Methods included from DSL

#add_brick, #detect_type, included, #module_name, #rb_file

Methods included from Output

#close_output, included, #open_output, #write, #writeln

Methods included from PrettyPrint

#fmt, #fmt_key, #fmt_string, included, #is_array_of_strings_hack, #is_multi_line_hack, #is_single_line, #is_single_line_hack, #pprint, #pprint_cfn_resource, #pprint_cfn_section, #pprint_cfn_template, #pprint_value, #prelude_code, #print_with_wrapper

Methods included from Simplify

included, #simplify

Methods included from Maintainer

#i_am_maintainer, included, #maintainer, #maintainer_comment, #print_maintainer

Methods included from Options

included, #parse_options, #setup_config, #setup_options

Constructor Details

#initializeBase

Returns a new instance of Base.



15
16
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
# File 'lib/aws/cfn/dsl/base.rb', line 15

def initialize
  super
  @output = []
  @config ||= {}

  # noinspection RubyStringKeysInHashInspection
  @formats = {
      'yaml' => 'yaml',
      'yml' => 'yaml',
      'yts' => 'yaml',
      'ytf' => 'yaml',
      'ytp' => 'yaml',
      'json' => 'json',
      'jml' => 'json',
      'jts' => 'json',
      'jtf' => 'json',
      'jtp' => 'json',
      'tpl' => 'json',
      'template' => 'json',
      'ruby' => 'ruby',
      'rb' => 'ruby',
  }

  @all_sections = %w{Mappings Parameters Conditions Resources Outputs}
  @valid_functions = %w(Fn::Base64 Fn::GetAtt Fn::GetAZs Fn::Join Fn::FindInMap Fn::Select Ref Fn::Equals Fn::If Fn::Not Condition Fn::And Fn::Or)

end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



9
10
11
# File 'lib/aws/cfn/dsl/base.rb', line 9

def items
  @items
end

#templateObject (readonly)

Returns the value of attribute template.



10
11
12
# File 'lib/aws/cfn/dsl/base.rb', line 10

def template
  @template
end

Instance Method Details

#ext2format(ext) ⇒ Object



43
44
45
# File 'lib/aws/cfn/dsl/base.rb', line 43

def ext2format(ext)
  @formats.has_key? ext ? @formats[ext] : nil
end

#format2exts(format) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/aws/cfn/dsl/base.rb', line 47

def format2exts(format)
  exts = @formats.select{ |_,v| v == format }
  if exts.size > 0
    exts.keys
  else
    []
  end
end

#formats_compatible?(format, match) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/aws/cfn/dsl/base.rb', line 56

def formats_compatible?(format, match)
  @formats[match] == @formats[format]
end

#load_template(file = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/aws/cfn/dsl/base.rb', line 65

def load_template(file=nil)
  if file
    filn = File.join(File.dirname(file), file)
    filn = File.expand_path(file) if @config[:expandedpaths]
    logStep "Loading #{filn}"
    begin
      abs = File.absolute_path(File.expand_path(file))
      unless File.exists?(abs) or @config[:directory].nil?
        abs = File.absolute_path(File.expand_path(File.join(@config[:directory],file)))
      end
    rescue
      # pass
    end
    if File.exists?(abs)
      case File.extname(File.basename(abs)).downcase
        # TODO: [2014-0-16 Christo] Replace these with @json_template_ext_regex
        when /json|js|template|jtf/
          @items = JSON.parse(File.read(abs))
        # TODO: [2014-0-16 Christo] Replace these with @yaml_template_ext_regex
        when /yaml|yml|ytf/
          @items = YAML.load(File.read(abs))
        else
          abort! "Unsupported file type for specification: #{file}"
      end
    else
      abort! "Unable to open template: #{abs}"
    end
    @items
  else
    nil
  end
end

#save_dsl(path = nil, parts = @items) ⇒ Object



60
61
62
63
# File 'lib/aws/cfn/dsl/base.rb', line 60

def save_dsl(path=nil,parts=@items)
  pprint(simplify(parts,true))
  @logger.step "*** DSL generated ***"
end