Class: Lono::OutputTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/lono/output_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(blueprint, template) ⇒ OutputTemplate

Returns a new instance of OutputTemplate.



3
4
5
# File 'lib/lono/output_template.rb', line 3

def initialize(blueprint, template)
  @blueprint, @template = blueprint, template
end

Instance Method Details

#check_template_exists(template_path) ⇒ Object

Check if the template exists and print friendly error message. Exits if it does not exist.



15
16
17
18
19
20
# File 'lib/lono/output_template.rb', line 15

def check_template_exists(template_path)
  unless File.exist?(template_path)
    puts "The template #{template_path} does not exist. Are you sure you use the right template name?  The template name does not require the extension.".color(:red)
    exit 1
  end
end

#dataObject



7
8
9
10
11
# File 'lib/lono/output_template.rb', line 7

def data
  template_path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
  check_template_exists(template_path)
  YAML.load(IO.read(template_path))
end

#optional_parametersObject



26
27
28
# File 'lib/lono/output_template.rb', line 26

def optional_parameters
  parameters.select { |logical_id, p| p["Default"] }
end

#parametersObject



30
31
32
# File 'lib/lono/output_template.rb', line 30

def parameters
  data["Parameters"] || []
end

#required_parametersObject



22
23
24
# File 'lib/lono/output_template.rb', line 22

def required_parameters
  parameters.reject { |logical_id, p| p["Default"] }
end