Class: Krane::RenderTask

Inherits:
Object
  • Object
show all
Defined in:
lib/krane/render_task.rb

Overview

Render templates

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, current_sha:, filenames: [], bindings:) ⇒ RenderTask

Initializes the render task



17
18
19
20
21
22
# File 'lib/krane/render_task.rb', line 17

def initialize(logger: nil, current_sha:, filenames: [], bindings:)
  @logger = logger || Krane::FormattedLogger.build
  @filenames = filenames.map { |path| File.expand_path(path) }
  @bindings = bindings
  @current_sha = current_sha
end

Instance Method Details

#run(*args) ⇒ Boolean

Runs the task, returning a boolean representing success or failure



27
28
29
30
31
32
# File 'lib/krane/render_task.rb', line 27

def run(*args)
  run!(*args)
  true
rescue Krane::FatalDeploymentError
  false
end

#run!(stream:) ⇒ nil

Runs the task, raising exceptions in case of issues



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/krane/render_task.rb', line 39

def run!(stream:)
  @logger.reset
  @logger.phase_heading("Initializing render task")

  ts = TemplateSets.from_dirs_and_files(paths: @filenames, logger: @logger)

  validate_configuration(ts)
  count = render_templates(stream, ts)

  @logger.summary.add_action("Successfully rendered #{count} template(s)")
  @logger.print_summary(:success)
rescue Krane::FatalDeploymentError
  @logger.print_summary(:failure)
  raise
end