class Aws::Cfn::Dsl::Base
Attributes
items[RW]
template[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
# 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
Public Instance Methods
ext2format(ext)
click to toggle source
# File lib/aws/cfn/dsl/base.rb, line 43 def ext2format(ext) @formats.has_key? ext ? @formats[ext] : nil end
format2exts(format)
click to toggle source
# 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)
click to toggle source
# File lib/aws/cfn/dsl/base.rb, line 56 def formats_compatible?(format, match) @formats[match] == @formats[format] end
load_template(file=nil)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
abort!(msg=nil,rc=1,st=nil)
click to toggle source
# File lib/aws/cfn/dsl/base.rb, line 100 def abort!(msg=nil,rc=1,st=nil) cfg = :trace st = (not (@opts[cfg].nil? or @opts[cfg].downcase.match(@on_yes_regex).nil?)) exp = '!!! Aborting !!!' exp += "\n"+caller[0..-1].join("\n") if st if @logger ::Logging::LogEvent.caller_index += 1 @logger.error msg if msg @logger.fatal exp else puts msg if msg puts exp end exit rc end