Class: Bosh::Director::Core::Templates::SourceErb

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/core/templates/source_erb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src_name, dest_name, erb_contents, template_name) ⇒ SourceErb

Returns a new instance of SourceErb.



8
9
10
11
12
13
14
# File 'lib/bosh/director/core/templates/source_erb.rb', line 8

def initialize(src_name, dest_name, erb_contents, template_name)
  @src_name = src_name
  @dest_name = dest_name
  erb = ERB.new(erb_contents)
  erb.filename = File.join(template_name, src_name)
  @erb = erb
end

Instance Attribute Details

#dest_nameObject (readonly)

Returns the value of attribute dest_name.



6
7
8
# File 'lib/bosh/director/core/templates/source_erb.rb', line 6

def dest_name
  @dest_name
end

#erbObject (readonly)

Returns the value of attribute erb.



6
7
8
# File 'lib/bosh/director/core/templates/source_erb.rb', line 6

def erb
  @erb
end

#src_nameObject (readonly)

Returns the value of attribute src_name.



6
7
8
# File 'lib/bosh/director/core/templates/source_erb.rb', line 6

def src_name
  @src_name
end

Instance Method Details

#render(context, logger) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bosh/director/core/templates/source_erb.rb', line 16

def render(context, logger)
  erb.result(context.get_binding)
  # rubocop:disable RescueException
rescue Exception => e
  # rubocop:enable RescueException

  logger.debug(e.inspect)
  line_index = e.backtrace.index { |l| l.include?(erb.filename) }
  line = line_index ? e.backtrace[line_index] : '(unknown):(unknown)'
  template_name, line = line.split(':')

  message = "Error filling in template '#{File.basename(template_name)}' (line #{line}: #{e})"

  logger.debug("#{message}\n#{e.backtrace.join("\n")}")
  raise message
end