Class: Fulmar::Domain::Service::ConfigRenderingService

Inherits:
Object
  • Object
show all
Defined in:
lib/fulmar/domain/service/config_rendering_service.rb

Overview

Renders templates of config files

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConfigRenderingService

Returns a new instance of ConfigRenderingService.



8
9
10
# File 'lib/fulmar/domain/service/config_rendering_service.rb', line 8

def initialize(config)
  @config = config
end

Instance Method Details

#renderObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fulmar/domain/service/config_rendering_service.rb', line 12

def render
  return unless @config[:config_templates]
  @config[:config_templates].each do |template_file|
    template = "#{@config[:local_path]}/#{template_file}"
    fail "Template filenames must end in .erb - '#{template}' does not" unless template[-4, 4] == '.erb'
    fail "Cannot render missing config file '#{template}'" unless File.exist? template

    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