class Fulmar::Domain::Service::TemplateRenderingService
Renders templates of config files
Public Class Methods
new(config)
click to toggle source
# File lib/fulmar/domain/service/template_rendering_service.rb, line 8 def initialize(config) @config = config end
Public Instance Methods
render()
click to toggle source
# File lib/fulmar/domain/service/template_rendering_service.rb, line 12 def render return unless @config[:templates] @config[:templates].each do |template_file| template = template_path(template_file) renderer = ERB.new(File.read(template)) result_path = File.dirname(template) + '/' + File.basename(template, '.erb') File.open(result_path, 'w') { |config_file| config_file.write(renderer.result(binding)) } end end
template_path(template_file)
click to toggle source
# File lib/fulmar/domain/service/template_rendering_service.rb, line 23 def template_path(template_file) template = "#{@config[:local_path]}/#{template_file}" raise "Template filenames must end in .erb - '#{template}' does not" unless template[-4, 4] == '.erb' raise "Cannot render missing config file '#{template}'" unless File.exist? template template end