Class: PackerTemplate
- Inherits:
-
Object
- Object
- PackerTemplate
- Defined in:
- lib/template.rb
Overview
instance of a single packer template with methods to validate and extract data
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #builders ⇒ Object
- #builders_hash ⇒ Object
-
#initialize(path) ⇒ PackerTemplate
constructor
A new instance of PackerTemplate.
- #json ⇒ Object
-
#validates? ⇒ Boolean
shell out to packer to validate the config files for correctness.
Constructor Details
#initialize(path) ⇒ PackerTemplate
25 26 27 28 29 |
# File 'lib/template.rb', line 25 def initialize(path) @path = File.(path) @name = File.basename(@path, '.json') @file = File.read(path) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/template.rb', line 23 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
23 24 25 |
# File 'lib/template.rb', line 23 def path @path end |
Instance Method Details
#builders ⇒ Object
35 36 37 |
# File 'lib/template.rb', line 35 def builders json['builders'].map { |b| b['name'] } end |
#builders_hash ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/template.rb', line 39 def builders_hash builders = {} json['builders'].each do |builder| builders[builder['name']] = builder['type'] end builders end |
#json ⇒ Object
31 32 33 |
# File 'lib/template.rb', line 31 def json @parsed || @parsed = JSON.parse(@file) end |
#validates? ⇒ Boolean
shell out to packer to validate the config files for correctness
48 49 50 51 52 |
# File 'lib/template.rb', line 48 def validates? Dir.chdir(File.dirname(@path)) `packer validate #{@path} 2>&1` $CHILD_STATUS.success? ? true : false end |