class Singel::PackerTemplate
instance of a single packer template with methods to validate and extract data
Attributes
name[RW]
path[RW]
Public Class Methods
new(path)
click to toggle source
# File lib/singel/template.rb 24 def initialize(path) 25 @path = File.expand_path(path) 26 @name = File.basename(@path, '.json') 27 @file = File.read(path) 28 end
Public Instance Methods
builders()
click to toggle source
# File lib/singel/template.rb 38 def builders 39 json['builders'].map { |b| b['name'] } 40 end
builders_hash()
click to toggle source
# File lib/singel/template.rb 42 def builders_hash 43 builders = {} 44 json['builders'].each do |builder| 45 builders[builder['name']] = builder['type'] 46 end 47 builders 48 end
json()
click to toggle source
# File lib/singel/template.rb 30 def json 31 @parsed || @parsed = JSON.parse(@file) 32 rescue JSON::ParserError 33 puts "Invalid JSON in the Packer config #{@name}.\nValidate your JSON before running Singel again.".to_red 34 STDOUT.flush 35 exit! 36 end
validates?()
click to toggle source
shell out to packer to validate the config files for correctness
# File lib/singel/template.rb 51 def validates? 52 Dir.chdir(File.dirname(@path)) 53 `packer validate #{@path} 2>&1` 54 $CHILD_STATUS.success? ? true : false 55 end