Class: Bosh::Template::Test::Template

Inherits:
Object
  • Object
show all
Includes:
PropertyHelper
Defined in:
lib/bosh/template/test/template.rb

Instance Method Summary collapse

Methods included from PropertyHelper

#copy_property, #lookup_property, #set_property, #sort_property, #validate_properties_format

Constructor Details

#initialize(job_spec_hash, template_path) ⇒ Template

Returns a new instance of Template.



9
10
11
12
# File 'lib/bosh/template/test/template.rb', line 9

def initialize(job_spec_hash, template_path)
  @job_spec_hash = job_spec_hash
  @template_path = template_path
end

Instance Method Details

#render(manifest_properties_hash, spec: InstanceSpec.new, consumes: []) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/bosh/template/test/template.rb', line 14

def render(manifest_properties_hash, spec: InstanceSpec.new, consumes: [])
  spec_hash = {}
  spec_hash['properties'] = hash_with_defaults(manifest_properties_hash)
  sanitized_hash_with_spec = spec_hash.merge(spec.to_h)
  sanitized_hash_with_spec['links'] = links_hash(consumes)

  binding = Bosh::Template::EvaluationContext.new(sanitized_hash_with_spec, nil).get_binding
  raise "No such file at #{@template_path}" unless File.exist?(@template_path)
  ERB.new(File.read(@template_path), safe_level = nil, trim_mode = '-').result(binding)
end