Class: Soaspec::TemplateReader
- Inherits:
-
Object
- Object
- Soaspec::TemplateReader
- Defined in:
- lib/soaspec/template_reader.rb
Overview
Handles reading templates for tests
Instance Attribute Summary collapse
-
#template_name ⇒ Object
Name of file where template is stored.
Instance Method Summary collapse
-
#file_location ⇒ String
Path to where template file is stored.
-
#render_body(template_name, test_values) ⇒ String
Body of template after determining test_values.
Instance Attribute Details
#template_name ⇒ Object
Name of file where template is stored
9 10 11 |
# File 'lib/soaspec/template_reader.rb', line 9 def template_name @template_name end |
Instance Method Details
#file_location ⇒ String
Returns Path to where template file is stored.
12 13 14 |
# File 'lib/soaspec/template_reader.rb', line 12 def file_location File.join(*Soaspec.template_folder, template_name) end |
#render_body(template_name, test_values) ⇒ String
Returns Body of template after determining test_values.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/soaspec/template_reader.rb', line 18 def render_body(template_name, test_values) test_values = IndifferentHash.new(test_values) # Allow test_values to be either Symbol or String test_values&.each do |key, value| instance_variable_set("@#{key}", value) end self.template_name = template_name unless File.exist? file_location raise "Cannot see file at #{file_location}. "\ "Global folder is '#{Soaspec.template_folder}' and filename is '#{template_name}'" end request_body = File.read file_location raise "Template at #{file_location} not parsed correctly" if request_body.strip.empty? ERB.new(request_body).result(binding) end |