Class: Lono::OutputTemplate
- Inherits:
-
Object
- Object
- Lono::OutputTemplate
- Defined in:
- lib/lono/output_template.rb
Instance Method Summary collapse
-
#check_template_exists(template_path) ⇒ Object
Check if the template exists and print friendly error message.
- #data ⇒ Object
-
#initialize(blueprint, template) ⇒ OutputTemplate
constructor
A new instance of OutputTemplate.
- #optional_parameters ⇒ Object
- #parameters ⇒ Object
- #required_parameters ⇒ Object
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 |
#data ⇒ Object
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_parameters ⇒ Object
26 27 28 |
# File 'lib/lono/output_template.rb', line 26 def optional_parameters parameters.select { |logical_id, p| p["Default"] } end |
#parameters ⇒ Object
30 31 32 |
# File 'lib/lono/output_template.rb', line 30 def parameters data["Parameters"] || [] end |
#required_parameters ⇒ Object
22 23 24 |
# File 'lib/lono/output_template.rb', line 22 def required_parameters parameters.reject { |logical_id, p| p["Default"] } end |