Sha256: b0d3fd0b0eed720d0f5d78a64e177f1dd4e8c0dac7dee67daff6124e3cf3040f

Contents?: true

Size: 608 Bytes

Versions: 31

Compression:

Stored size: 608 Bytes

Contents

# frozen_string_literal: true
require "forwardable"

module ActiveMocker
  class TemplateCreator
    def initialize(erb_template:, file_out: nil, binding:, post_process: -> (str) { str })
      @erb_template = erb_template
      @binding      = binding
      @file_out     = file_out || Tempfile.new("TemplateModel")
      @post_process = post_process
    end

    def render
      template = ERB.new(erb_template.read, nil, ">")
      file_out.write post_process.call(template.result(binding))
      file_out
    end

    private

    attr_reader :erb_template, :binding, :file_out, :post_process
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
active_mocker-2.6.2 lib/active_mocker/template_creator.rb
active_mocker-2.6.1.beta2 lib/active_mocker/template_creator.rb
active_mocker-2.6.1.beta lib/active_mocker/template_creator.rb
active_mocker-2.6.0 lib/active_mocker/template_creator.rb
active_mocker-2.5.4 lib/active_mocker/template_creator.rb
active_mocker-2.5.3 lib/active_mocker/template_creator.rb
active_mocker-2.5.2 lib/active_mocker/template_creator.rb
active_mocker-2.5.1 lib/active_mocker/template_creator.rb
active_mocker-2.5.1.pre lib/active_mocker/template_creator.rb
active_mocker-2.5.0 lib/active_mocker/template_creator.rb
active_mocker-2.4.4 lib/active_mocker/template_creator.rb
active_mocker-2.4.3 lib/active_mocker/template_creator.rb
active_mocker-2.4.2 lib/active_mocker/template_creator.rb
active_mocker-2.4.1 lib/active_mocker/template_creator.rb
active_mocker-2.4.0 lib/active_mocker/template_creator.rb
active_mocker-2.4.0.pre5 lib/active_mocker/template_creator.rb
active_mocker-2.3.4 lib/active_mocker/template_creator.rb
active_mocker-2.4.0.pre4 lib/active_mocker/template_creator.rb
active_mocker-2.4.0.pre3 lib/active_mocker/template_creator.rb
active_mocker-2.4.0.pre2 lib/active_mocker/template_creator.rb