Class: PEBuild::Provisioner::PEBootstrap::AnswersFile Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pe_build/provisioner/pe_bootstrap/answers_file.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A sub-provisioner which generates answer file content.

This is an internal provisioner which is invoked by PEBuild::Provisioner::PEBootstrap.

Instance Method Summary collapse

Constructor Details

#initialize(machine, config, work_dir) ⇒ AnswersFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AnswersFile.

Parameters:

  • machine (Vagrant::Machine)
  • config (Object < Vagrant.plugin('2', :config)])

    onfig [Object < Vagrant.plugin('2', :config)]

  • work_dir (String)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pe_build/provisioner/pe_bootstrap/answers_file.rb', line 16

def initialize(machine, config, work_dir)
  @machine, @config = machine, config
  @work_dir = Pathname.new(work_dir)

  @logger = Log4r::Logger.new('vagrant::provisioner::pe_bootstrap::answers_file')

  @answer_dir  = @work_dir.join('answers')
  @output_file = @answer_dir.join "#{@machine.name}.txt"

  set_template_path
end

Instance Method Details

#generateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
# File 'lib/pe_build/provisioner/pe_bootstrap/answers_file.rb', line 28

def generate
  @logger.info "Writing answers file for #{@machine.inspect} to #{@output_file}"
  @answer_dir.mkpath unless @answer_dir.exist?

  @output_file.open('w') { |fh| fh.write(render_answers) }
end

#render_answersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
40
41
42
# File 'lib/pe_build/provisioner/pe_bootstrap/answers_file.rb', line 35

def render_answers
  answer_template = template_data
  unless @config.answer_extras.empty?
    answer_template += ("\n" + @config.answer_extras.map {|e| e.to_s}.join("\n") + "\n")
  end

  ERB.new(answer_template).result(binding)
end