Class: Consul::Async::ConsulTemplateRender

Inherits:
Object
  • Object
show all
Defined in:
lib/consul/async/consul_template_render.rb

Overview

Object handling the whole rendering of a template It stores the input, the output and flags about last result being modified or simply readiness information about whether the template did receive all data to be fully rendered

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_manager, template_file, output_file, hot_reload_failure: 'die', params: {}) ⇒ ConsulTemplateRender

Returns a new instance of ConsulTemplateRender.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/consul/async/consul_template_render.rb', line 28

def initialize(template_manager, template_file, output_file, hot_reload_failure: 'die', params: {})
  @hot_reload_failure = hot_reload_failure
  @template_file = template_file
  @output_file = output_file
  @template_manager = template_manager
  @last_result = ''
  @last_result = File.read(output_file) if File.exist? output_file
  @template = load_template
  @params = params
  @was_rendered_once = false
end

Instance Attribute Details

#hot_reload_failureObject (readonly)

Returns the value of attribute hot_reload_failure.



27
28
29
# File 'lib/consul/async/consul_template_render.rb', line 27

def hot_reload_failure
  @hot_reload_failure
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



27
28
29
# File 'lib/consul/async/consul_template_render.rb', line 27

def output_file
  @output_file
end

#paramsObject (readonly)

Returns the value of attribute params.



27
28
29
# File 'lib/consul/async/consul_template_render.rb', line 27

def params
  @params
end

#template_fileObject (readonly)

Returns the value of attribute template_file.



27
28
29
# File 'lib/consul/async/consul_template_render.rb', line 27

def template_file
  @template_file
end

#template_file_ctimeObject (readonly)

Returns the value of attribute template_file_ctime.



27
28
29
# File 'lib/consul/async/consul_template_render.rb', line 27

def template_file_ctime
  @template_file_ctime
end

Instance Method Details

#render(tpl = @template, current_template_info: _build_default_template_info) ⇒ Object



40
41
42
# File 'lib/consul/async/consul_template_render.rb', line 40

def render(tpl = @template, current_template_info: _build_default_template_info)
  @template_manager.render(tpl, template_file, params, current_template_info: current_template_info)
end

#runObject



44
45
46
47
48
# File 'lib/consul/async/consul_template_render.rb', line 44

def run
  hot_reloaded = hot_reload_if_needed
  was_success, modified, last_result = write
  ConsulTemplateRenderedResult.new(template_file, output_file, hot_reloaded, was_success, modified, last_result)
end