Class: Bosh::Director::Core::Templates::JobTemplateRenderer
- Inherits:
-
Object
- Object
- Bosh::Director::Core::Templates::JobTemplateRenderer
- Defined in:
- lib/bosh/director/core/templates/job_template_renderer.rb
Instance Attribute Summary collapse
-
#monit_erb ⇒ Object
readonly
Returns the value of attribute monit_erb.
-
#source_erbs ⇒ Object
readonly
Returns the value of attribute source_erbs.
Instance Method Summary collapse
-
#initialize(name, monit_erb, source_erbs, logger) ⇒ JobTemplateRenderer
constructor
A new instance of JobTemplateRenderer.
- #render(spec) ⇒ Object
Constructor Details
#initialize(name, monit_erb, source_erbs, logger) ⇒ JobTemplateRenderer
Returns a new instance of JobTemplateRenderer.
11 12 13 14 15 16 |
# File 'lib/bosh/director/core/templates/job_template_renderer.rb', line 11 def initialize(name, monit_erb, source_erbs, logger) @name = name @monit_erb = monit_erb @source_erbs = source_erbs @logger = logger end |
Instance Attribute Details
#monit_erb ⇒ Object (readonly)
Returns the value of attribute monit_erb.
9 10 11 |
# File 'lib/bosh/director/core/templates/job_template_renderer.rb', line 9 def monit_erb @monit_erb end |
#source_erbs ⇒ Object (readonly)
Returns the value of attribute source_erbs.
9 10 11 |
# File 'lib/bosh/director/core/templates/job_template_renderer.rb', line 9 def source_erbs @source_erbs end |
Instance Method Details
#render(spec) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bosh/director/core/templates/job_template_renderer.rb', line 18 def render(spec) template_context = Bosh::Template::EvaluationContext.new(adjust_template_properties(spec,@name)) monit = monit_erb.render(template_context, @logger) errors = [] rendered_files = source_erbs.map do |source_erb| begin file_contents = source_erb.render(template_context, @logger) rescue Exception => e errors.push e end RenderedFileTemplate.new(source_erb.src_name, source_erb.dest_name, file_contents) end if errors.length > 0 = "Unable to render templates for job '#{@name}'. Errors are:" errors.each do |e| = "#{message}\n - #{e.message.gsub(/\n/, "\n ")}" end raise end RenderedJobTemplate.new(@name, monit, rendered_files) end |