Class: Aws::Cfn::Dsl::Base
- Inherits:
-
Object
- Object
- Aws::Cfn::Dsl::Base
- Includes:
- DLDInternet::Mixlib::Logging
- Defined in:
- lib/aws/cfn/dsl/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #load_template(file = nil) ⇒ Object
- #save_dsl(path = nil, parts = @items) ⇒ Object
Constructor Details
#initialize ⇒ Base
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
#items ⇒ Object
Returns the value of attribute items.
9 10 11 |
# File 'lib/aws/cfn/dsl/base.rb', line 9 def items @items end |
#output ⇒ Object (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.(file)) unless File.exists?(abs) or @opts[:output].nil? abs = File.absolute_path(File.(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 |