Sha256: d1c8bd96db83de96bd1cfa495fac25dbbe05b1df9b4c616462a61eb4c554dc33

Contents?: true

Size: 915 Bytes

Versions: 10

Compression:

Stored size: 915 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_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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
fulmar-1.5.2 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.5.1 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.5.0 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.4.2 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.4.1 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.4.0 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.3.0 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.2.1 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.2.0 lib/fulmar/domain/service/config_rendering_service.rb
fulmar-1.1.0 lib/fulmar/domain/service/config_rendering_service.rb