Class: Idlc::Build::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/iapi-idlc-sdk-build/template.rb

Instance Method Summary collapse

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

#renderObject



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_dirObject



9
10
11
# File 'lib/iapi-idlc-sdk-build/template.rb', line 9

def templates_dir
  "#{__dir__}/templates/#{@metadata['build_stage'].value}"
end

#writeObject



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