Class: Hygroscope::Template
- Inherits:
-
Object
- Object
- Hygroscope::Template
- Defined in:
- lib/hygroscope/template.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #compress ⇒ Object
-
#initialize(path) ⇒ Template
constructor
A new instance of Template.
- #parameters ⇒ Object
-
#process ⇒ Object
Process a set of files with cfoo and return JSON.
-
#process_to_file ⇒ Object
Process a set of files with cfoo and write JSON to a temporary file.
- #validate ⇒ Object
Constructor Details
#initialize(path) ⇒ Template
Returns a new instance of Template.
11 12 13 |
# File 'lib/hygroscope/template.rb', line 11 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/hygroscope/template.rb', line 9 def path @path end |
Instance Method Details
#compress ⇒ Object
35 36 37 |
# File 'lib/hygroscope/template.rb', line 35 def compress JSON.parse(process).to_json end |
#parameters ⇒ Object
39 40 41 42 |
# File 'lib/hygroscope/template.rb', line 39 def parameters template = JSON.parse(process) template['Parameters'] || [] end |
#process ⇒ Object
Process a set of files with cfoo and return JSON
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hygroscope/template.rb', line 16 def process return @template if @template out = StringIO.new err = StringIO.new files = Dir.glob(File.join(@path, '*.{yml,yaml}')) cfoo = Cfoo::Factory.new(out, err).cfoo Dir.chdir('/') do cfoo.process(*files) end fail(TemplateYamlParseError, err.string) unless err.string.empty? @template = out.string @template end |
#process_to_file ⇒ Object
Process a set of files with cfoo and write JSON to a temporary file
45 46 47 48 49 50 51 52 53 |
# File 'lib/hygroscope/template.rb', line 45 def process_to_file file = Tempfile.new(['hygroscope-', '.json']) file.write(process) file.close at_exit { file.unlink } file end |
#validate ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hygroscope/template.rb', line 55 def validate # Parsing the template to JSON and then re-outputting it is a form of # compression (removing all extra spaces) to keep within the 50KB limit # for CloudFormation templates. template = compress begin stack = Hygroscope::Stack.new('template-validator') stack.client.validate_template(template_body: template) rescue => e raise e end end |