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

Inherits:
Object
  • Object
show all
Includes:
DLDInternet::Mixlib::Logging
Defined in:
lib/aws/cfn/dsl/base.rb

Direct Known Subclasses

Main

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

  lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
      :trace => :blue,
      :debug => :cyan,
      :info  => :green,
      :step  => :green,
      :warn  => :yellow,
      :error => :red,
      :fatal => :red,
      :todo  => :purple,
  })
  scheme = lcs.scheme
  scheme['trace'] = "\e[38;5;33m"
  scheme['fatal'] = "\e[38;5;89m"
  scheme['todo']  = "\e[38;5;55m"
  lcs.scheme scheme
  @config[:log_opts] = lambda{|mlll| {
      :pattern      => "%#{mlll}l: %m %C\n",
      :date_pattern => '%Y-%m-%d %H:%M:%S',
      :color_scheme => 'compiler'
  }
  }
  @config[:log_level] = :info
  @logger = getLogger(@config)

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

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#load_template(file = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/aws/cfn/dsl/base.rb', line 51

def load_template(file=nil)
  if file
    logStep "Loading #{file}"
    begin
      abs = File.absolute_path(File.expand_path(file))
      unless File.exists?(abs) or @opts[:output].nil?
        abs = File.absolute_path(File.expand_path(File.join(@opts[:output],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
  end
end

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



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

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