class CC::Config::Validation::EngineValidator

Constants

RECOGNIZED_KEYS

Attributes

data[R]
errors[R]
warnings[R]

Public Class Methods

new(data, legacy: false) click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 18
def initialize(data, legacy: false)
  @data = data
  @legacy = legacy

  @errors = []
  @warnings = []

  validate
end

Public Instance Methods

valid?() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 28
def valid?
  errors.none?
end

Private Instance Methods

legacy?() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 36
def legacy?
  @legacy
end
validate() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 40
def validate
  validate_root
  return unless data.is_a?(Hash)

  validate_key_type("enabled", [TrueClass, FalseClass])
  validate_key_type("channel", String)
  validate_key_type("config", [String, Hash])
  validate_key_type("exclude_patterns", Array)
  if legacy?
    validate_exclude_paths
  end

  validate_checks
  validate_exclude_fingerprints

  if legacy?
    warn_unrecognized_keys(RECOGNIZED_KEYS + %w[exclude_paths])
  else
    warn_unrecognized_keys(RECOGNIZED_KEYS)
  end
end
validate_checks() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 70
def validate_checks
  return unless validate_key_type("checks", Hash)

  data.fetch("checks", {}).each do |_check_name, check_data|
    validator = CheckValidator.new(check_data)
    errors.push(*validator.errors)
    warnings.push(*validator.warnings)
  end
end
validate_exclude_fingerprints() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 87
def validate_exclude_fingerprints
  validate_key_type("exclude_fingerprints", Array)
end
validate_exclude_paths() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 80
def validate_exclude_paths
  validate_key_type("exclude_paths", [Array, String])
  if data.key?("exclude_paths")
    warnings << "'exclude_paths' has been deprecated, please use 'exclude_patterns' instead"
  end
end
validate_root() click to toggle source
# File lib/cc/config/validation/engine_validator.rb, line 62
def validate_root
  if !data.is_a?(Hash) && ![true, false].include?(data)
    errors << "section must be a boolean or a hash"
    return false
  end
  true
end