Class: Cumuliform::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/cumuliform/runner.rb

Overview

The Runner class reads a template, execute it and write the generated JSON to a file

Class Method Summary collapse

Class Method Details

.process(input_path, output_path) ⇒ void

This method returns an undefined value.

Reads the template file at input_path, parses and executes it to generate CloudFormation JSON which is written to output_path

Parameters:

  • input_path (String)

    The path to the input Cumuliform template file

  • output_path (String)

    The path to the output CloudFormation JSON template file



25
26
27
28
29
30
31
# File 'lib/cumuliform/runner.rb', line 25

def self.process(input_path, output_path)
  input_path = Pathname.new(input_path)
  output_path = Pathname.new(output_path)

  template = process_io(input_path.open)
  output_path.open('w:utf-8') { |f| f.write(template.to_json) }
end

.process_io(io) ⇒ Template

Processes an IO object which will, when read, return a Cumuliform template file.

Parameters:

  • io (IO)

    The IO-like object containing the template

Returns:

  • (Template)

    the parsed Cumuliform::Template object



13
14
15
16
17
18
# File 'lib/cumuliform/runner.rb', line 13

def self.process_io(io)
  mod = Module.new
  path = io.respond_to?(:path) ? io.path : nil
  args = [io.read, path].compact
  template = mod.class_eval(*args)
end