Class: Idlc::Build::Template
- Inherits:
-
Object
- Object
- Idlc::Build::Template
- Defined in:
- lib/iapi-idlc-sdk-build/template.rb
Instance Method Summary collapse
-
#initialize(metadata, output_file) ⇒ Template
constructor
A new instance of Template.
- #render ⇒ Object
- #templates_dir ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(metadata, output_file) ⇒ Template
Returns a new instance of Template.
4 5 6 7 |
# File 'lib/iapi-idlc-sdk-build/template.rb', line 4 def initialize(, output_file) @metadata = @output_file = output_file end |
Instance Method Details
#render ⇒ Object
13 14 15 16 17 18 |
# File 'lib/iapi-idlc-sdk-build/template.rb', line 13 def render tpl = File.read("#{templates_dir}/build.json.erb") renderer = ERB.new(tpl) renderer.result(binding) end |
#templates_dir ⇒ Object
9 10 11 |
# File 'lib/iapi-idlc-sdk-build/template.rb', line 9 def templates_dir "#{__dir__}/templates/#{@metadata['build_stage'].value}" end |
#write ⇒ Object
20 21 22 23 |
# File 'lib/iapi-idlc-sdk-build/template.rb', line 20 def write # Write rendered template to output_file File.open(@output_file, 'w') { |file| file.write(render) } end |