Class: Generator::TestFileGenerator
- Inherits:
-
Object
- Object
- Generator::TestFileGenerator
- 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
-
#generate ⇒ void
Generates the test file by rendering the template using the provided attributes.
-
#initialize(config) ⇒ TestFileGenerator
constructor
A new instance of TestFileGenerator.
- #test_file_summary ⇒ Object
Constructor Details
#initialize(config) ⇒ TestFileGenerator
Returns a new instance of TestFileGenerator.
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
#generate ⇒ void
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_summary ⇒ Object
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 |