Sha256: c76f8e2d580327148d3a068c03afcfff10db6e85b522723268f06070438e89ed

Contents?: true

Size: 844 Bytes

Versions: 4

Compression:

Stored size: 844 Bytes

Contents

require 'erb'

module Fulmar
  module Domain
    module Service
      # Renders templates of config files
      class ConfigRenderingService
        def initialize(config)
          @config = config
        end

        def render
          return unless @config[:config_templates]
          @config[:config_templates].each do |template|
            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
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fulmar-1.0.0 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-0.6.5 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-0.6.4 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-0.6.3 lib/fulmar/domain/service/config_rendering_service.rb