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, template_name, monit_erb, source_erbs, logger) ⇒ JobTemplateRenderer
constructor
A new instance of JobTemplateRenderer.
- #render(spec) ⇒ Object
Constructor Details
#initialize(name, template_name, monit_erb, source_erbs, logger) ⇒ JobTemplateRenderer
Returns a new instance of JobTemplateRenderer.
11 12 13 14 15 16 17 |
# File 'lib/bosh/director/core/templates/job_template_renderer.rb', line 11 def initialize(name, template_name, monit_erb, source_erbs, logger) @name = name @template_name = template_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
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 47 48 49 50 51 52 |
# File 'lib/bosh/director/core/templates/job_template_renderer.rb', line 19 def render(spec) if spec['properties_need_filtering'] spec = remove_unused_properties(spec) end template_context = Bosh::Template::EvaluationContext.new(Bosh::Common::DeepCopy.copy(spec)) monit = monit_erb.render(template_context, @logger) errors = [] rendered_files = source_erbs.map do |source_erb| template_context = Bosh::Template::EvaluationContext.new(Bosh::Common::DeepCopy.copy(spec)) 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| = "#{}\n - #{e..gsub(/\n/, "\n ")}" end raise end RenderedJobTemplate.new(@name, monit, rendered_files) end |