Class: Generator::TestFileGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/au_ps_inferno/generator/test_file_generator.rb

Overview

TestFile generator. Use config to generate the test file. Config is: template_file_path, output_file_path, optional output_base, and attributes. All template files should be in the templates folder.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TestFileGenerator

Returns a new instance of TestFileGenerator.

Parameters:

  • config (Hash)

    configuration hash

Options Hash (config):

  • :template_file_path (String)

    Relative path to the ERB template file

  • :output_file_path (String)

    Relative path or filename for the generated file

  • :output_base (String)

    Optional. When set, output is written to output_base/output_file_path (e.g. lib/au_ps_inferno/1.0.0-preview/au_ps_sections_validation_group). When omitted, uses generator/tests/.

  • :attributes (Hash)

    Hash of variables made available to the ERB template



17
18
19
20
21
22
# File 'lib/au_ps_inferno/generator/test_file_generator.rb', line 17

def initialize(config)
  @template_file_path = config[:template_file_path]
  @output_file_path = config[:output_file_path]
  @output_base = config[:output_base]
  @attributes = config[:attributes]
end

Instance Method Details

#generatevoid

This method returns an undefined value.

Generates the test file by rendering the template using the provided attributes. The result is saved to output_base/output_file_path when output_base is set, else under generator/tests/.



28
29
30
31
32
33
34
# File 'lib/au_ps_inferno/generator/test_file_generator.rb', line 28

def generate
  template = ERB.new(File.read(template_file_path))
  path = output_file_path
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, template.result(erb_binding))
  puts "Test file generated: #{path}"
end

#test_file_summaryObject



36
37
38
39
40
41
# File 'lib/au_ps_inferno/generator/test_file_generator.rb', line 36

def test_file_summary
  {
    file_path: output_file_path,
    attributes: @attributes
  }
end