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

Inherits:
Object
  • 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
# 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',
  }


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



41
42
43
# File 'lib/aws/cfn/dsl/base.rb', line 41

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

#format2exts(format) ⇒ Object



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

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)


54
55
56
# File 'lib/aws/cfn/dsl/base.rb', line 54

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

#load_template(file = nil) ⇒ Object



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

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
        when /json|js/
          @items = JSON.parse(File.read(abs))
        when /yaml|yml/
          @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



58
59
60
61
# File 'lib/aws/cfn/dsl/base.rb', line 58

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