Class: Puppet::Pops::Binder::Hiera2::ConfigChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/binder/hiera2/config_checker.rb

Overview

Validates the consistency of a Hiera2::Config

Instance Method Summary collapse

Constructor Details

#initialize(diagnostics) ⇒ ConfigChecker

Create an instance with a diagnostic producer that will receive the result during validation

Parameters:



8
9
10
# File 'lib/puppet/pops/binder/hiera2/config_checker.rb', line 8

def initialize(diagnostics)
  @diagnostics = diagnostics
end

Instance Method Details

#validate(data, config_file) ⇒ Object

Validate the consistency of the given data. Diagnostics will be emitted to the DiagnosticProducer that was set when this checker was created

Parameters:

  • data (Object)

    The data read from the config file

  • config_file (String)

    The full path of the file. Used in error messages



17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/pops/binder/hiera2/config_checker.rb', line 17

def validate(data, config_file)
  if data.is_a?(Hash)
    # If the version is missing, it is not meaningful to continue
    return unless check_version(data['version'], config_file)
    check_hierarchy(data['hierarchy'], config_file)
    check_backends(data['backends'], config_file)
  else
    @diagnostics.accept(Issues::CONFIG_IS_NOT_HASH, config_file)
  end
end