Sha256: ae8706a60342bb095afdcb55e72106dfeeb954446240858a76ccd99320e1cd3e

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'yaml'
require_relative '../cli/silencer'
Reek::CLI::Silencer.without_warnings { require 'kwalify' }
require_relative '../errors/config_file_error'

module Reek
  module Configuration
    #
    # Schema validator module.
    #
    class SchemaValidator
      SCHEMA_FILE_PATH = File.expand_path('./schema.yml', __dir__)

      def initialize(configuration)
        @configuration = configuration
        @validator = CLI::Silencer.without_warnings do
          schema_file = Kwalify::Yaml.load_file(SCHEMA_FILE_PATH)
          Kwalify::Validator.new(schema_file)
        end
      end

      def validate
        errors = CLI::Silencer.without_warnings { @validator.validate @configuration }
        return if !errors || errors.empty?
        raise Errors::ConfigFileError, error_message(errors)
      end

      private

      # :reek:UtilityFunction
      def error_message(errors)
        "We found some problems with your configuration file: #{CLI::Silencer.silently { errors.join(', ') }}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-5.0.2 lib/reek/configuration/schema_validator.rb
reek-5.0.1 lib/reek/configuration/schema_validator.rb
reek-5.0.0 lib/reek/configuration/schema_validator.rb