Class: ActiveMocker::TemplateCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mocker/template_creator.rb

Instance Method Summary collapse

Constructor Details

#initialize(erb_template:, file_out: nil, binding:, post_process: -> (str) { str }) ⇒ TemplateCreator

Returns a new instance of TemplateCreator.



6
7
8
9
10
11
# File 'lib/active_mocker/template_creator.rb', line 6

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

Instance Method Details

#renderObject



13
14
15
16
17
# File 'lib/active_mocker/template_creator.rb', line 13

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