Class: Guard::Bosh::TemplateChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/bosh/template_checker.rb

Overview

Encapsulates building the apply spec, and rendering job templates against it to identify errors.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployment_manifest:, properties_calculator:, apply_specification:, template_renderer:) ⇒ TemplateChecker

Returns a new instance of TemplateChecker.



15
16
17
18
19
20
21
22
23
# File 'lib/guard/bosh/template_checker.rb', line 15

def initialize(deployment_manifest:,
               properties_calculator:,
               apply_specification:,
               template_renderer:)
  @deployment_manifest = deployment_manifest
  @properties_calculator = properties_calculator
  @apply_specification = apply_specification
  @template_renderer = template_renderer
end

Class Method Details

.apply_specification(deployment_manifest, release_dir) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/guard/bosh/template_checker.rb', line 54

def self.apply_specification(deployment_manifest, release_dir)
  ApplySpecification.new(
    deployment_manifest: deployment_manifest,
    network_generator: NetworkGenerator.new,
    package_resolver: PackageResolver.new(release_dir)
  )
end

.build(deployment_manifest:, release_dir:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/guard/bosh/template_checker.rb', line 35

def self.build(deployment_manifest:, release_dir:)
  new(
    deployment_manifest: deployment_manifest,
    properties_calculator:
      properties_calculator(deployment_manifest, release_dir),
    apply_specification:
      apply_specification(deployment_manifest, release_dir),
    template_renderer: TemplateRenderer.new
  )
end

.properties_calculator(deployment_manifest, release_dir) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/guard/bosh/template_checker.rb', line 46

def self.properties_calculator(deployment_manifest, release_dir)
  EffectivePropertiesCalculator.new(loaders: [
    JobDefaultPropertiesLoader.new(release_dir: release_dir),
    GlobalPropertiesLoader.new(deployment_manifest: deployment_manifest),
    JobPropertiesLoader.new(deployment_manifest: deployment_manifest)
  ])
end

Instance Method Details

#check(manifest_job_name:, job_name:, template:) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/guard/bosh/template_checker.rb', line 25

def check(manifest_job_name:, job_name:, template:)
  properties = @properties_calculator.calculate_effective_properties(
    manifest_job_name: manifest_job_name, job_name: job_name)
  apply_spec = @apply_specification.generate(
    properties: properties,
    job_name: manifest_job_name
  )
  @template_renderer.render(context: apply_spec, template: template)
end