Sha256: 1e40ba0eff08bbf98deb2be5933a80efde8f213e1c0812ac2e81f4ad47188625

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

require_relative '../errors/config_file_error'
require_relative 'schema'

module Reek
  module Configuration
    #
    # Schema validator module.
    #
    class SchemaValidator
      def initialize(configuration)
        @configuration = configuration
        config_directories = configuration['directories']&.keys || []
        @validator = Reek::Configuration::Schema.schema(config_directories)
      end

      def validate
        result = @validator.call(@configuration)
        return if result.success?

        raise Errors::ConfigFileError, error_message(result.errors)
      rescue NoMethodError
        raise Errors::ConfigFileError, 'unrecognized configuration data'
      end

      private

      # :reek:UtilityFunction
      def error_message(errors)
        messages = errors.map do |error|
          "[/#{error.path.join('/')}] #{error.text}."
        end.join("\n")
        "\n#{messages}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-6.4.0 lib/reek/configuration/schema_validator.rb
reek-6.3.0 lib/reek/configuration/schema_validator.rb
reek-6.2.0 lib/reek/configuration/schema_validator.rb