Class: Reek::Configuration::SchemaValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/configuration/schema_validator.rb

Overview

Schema validator module.

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ SchemaValidator

Returns a new instance of SchemaValidator.



12
13
14
15
16
# File 'lib/reek/configuration/schema_validator.rb', line 12

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

Instance Method Details

#error_message(errors) ⇒ Object (private)

:reek:UtilityFunction



30
31
32
33
34
35
# File 'lib/reek/configuration/schema_validator.rb', line 30

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

#validateObject



18
19
20
21
22
23
24
25
# File 'lib/reek/configuration/schema_validator.rb', line 18

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