Sha256: b05c29df01d78566c77e89a559a02de039dcfeace89153ea8104eba3eab3ac31

Contents?: true

Size: 1.04 KB

Versions: 25

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

25 entries across 23 versions & 2 rubygems

Version Path
reek-6.1.4 lib/reek/configuration/schema_validator.rb
reek-6.1.3 lib/reek/configuration/schema_validator.rb
reek-6.1.2 lib/reek/configuration/schema_validator.rb
reek-6.1.1 lib/reek/configuration/schema_validator.rb
reek-6.1.0 lib/reek/configuration/schema_validator.rb
reek-6.0.6 lib/reek/configuration/schema_validator.rb
reek-6.0.5 lib/reek/configuration/schema_validator.rb
reek-6.0.4 lib/reek/configuration/schema_validator.rb
reek-6.0.3 lib/reek/configuration/schema_validator.rb
reek-6.0.2 lib/reek/configuration/schema_validator.rb
reek-6.0.1 lib/reek/configuration/schema_validator.rb
reek-6.0.0 lib/reek/configuration/schema_validator.rb
reek-5.6.0 lib/reek/configuration/schema_validator.rb
reek-5.5.0 lib/reek/configuration/schema_validator.rb
reek-5.4.1 lib/reek/configuration/schema_validator.rb
reek-5.4.0 lib/reek/configuration/schema_validator.rb
reek-5.3.2 lib/reek/configuration/schema_validator.rb
reek-5.3.1 lib/reek/configuration/schema_validator.rb
reek-5.3.0 lib/reek/configuration/schema_validator.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/lib/reek/configuration/schema_validator.rb