module Diffend::Configs::Validator

Class responsible for validating the config from .diffend.yml

Constants

KNOWN_KEYS

List of known config keys

UUID_FORMAT

Imported from github.com/assaf/uuid/blob/master/lib/uuid.rb#L199

UUID_KEYS

List of known uuid keys

Public Class Methods

call(config) click to toggle source

@param config [Diffend::Config]

# File lib/diffend/configs/validator.rb, line 30
def call(config)
  KNOWN_KEYS.each_key do |key|
    if missing?(config, key)
      config.errors << ErrorMessages.missing_key(key)
      next
    end

    config.errors << ErrorMessages.invalid_key(config, key) if invalid?(config, key)
  end

  UUID_KEYS.each do |key|
    next if valid_uuid?(config, key)

    config.errors << ErrorMessages.invalid_uuid(key)
  end
end

Private Class Methods

invalid?(config, key) click to toggle source

@param config [Diffend::Config] @param key [String]

@return [Boolean] true if we are missing a key, false otherwise

# File lib/diffend/configs/validator.rb, line 63
def invalid?(config, key)
  !KNOWN_KEYS[key].include?(config.public_send(key).class)
end
missing?(config, key) click to toggle source

@param config [Diffend::Config] @param key [String]

@return [Boolean] true if we are missing a key, false otherwise

# File lib/diffend/configs/validator.rb, line 53
def missing?(config, key)
  value = config.public_send(key)

  value.nil? || (value.respond_to?(:empty?) && value.empty?)
end
valid_uuid?(config, key) click to toggle source

@param config [Diffend::Config] @param key [String]

@return [Boolean] true if key has a valid uuid, false otherwise

# File lib/diffend/configs/validator.rb, line 71
def valid_uuid?(config, key)
  UUID_FORMAT.match?(config.public_send(key))
end