Class: ConvertSdk::ConfigValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/convert_sdk/config_validator.rb

Overview

The fail-fast validation rules for Config — the SDK's only raising surface.

ConfigValidator holds every presence/type rule for the configuration surface, extracted from Config so the surface class stays focused on naming-world translation and typed readers while the (uniform, table-like) validation rules live in one cohesive place. Every violation raises a stdlib ArgumentError naming the offending option and the expected type; there is no custom exception hierarchy anywhere in the SDK (Decision 3).

Rules:

  • presence — at least one of sdk_key / data must be present (FR6);
  • strings — sdk_key / sdk_key_secret / environment / config_endpoint / track_endpoint / negation must be String (nil accepted for the optional ones); data must be a Hash when present;
  • integers — max_traffic / hash_seed / event_batch_size;
  • intervals — data_refresh_interval / flush_interval are Numeric or nil (nil = timer-off); open_timeout / read_timeout are Numeric;
  • booleans — keys_case_sensitive / tracking (strict true/false);
  • log level — must be one of the LogLevel values;
  • cache level (qs-02) — must be nil or the String "low";
  • debug token (qs-03) — must be nil or a String (no fixed allow-list).

Constant Summary collapse

LOG_LEVEL_VALUES =

The accepted LogLevel integer values (TRACE..SILENT).

[
  LogLevel::TRACE, LogLevel::DEBUG, LogLevel::INFO,
  LogLevel::WARN, LogLevel::ERROR, LogLevel::SILENT
].freeze
CACHE_LEVEL_VALUES =

The accepted cache_level values (qs-02): nil (no-op) or "low".

[nil, "low"].freeze

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ ConfigValidator

Returns a new instance of ConfigValidator.

Parameters:

  • values (Hash{Symbol=>Object})

    the merged option values, keyed by the public snake_case option names (the ConvertSdk::Config::DEFAULTS keys).



38
39
40
# File 'lib/convert_sdk/config_validator.rb', line 38

def initialize(values)
  @values = values
end

Instance Method Details

#validate!void

This method returns an undefined value.

Run every rule. The first violation raises; presence is checked first so a wholly-empty config reports the most useful fault.

Raises:

  • (ArgumentError)

    on any presence/type violation.



47
48
49
50
51
52
53
54
55
# File 'lib/convert_sdk/config_validator.rb', line 47

def validate!
  validate_presence!
  validate_strings!
  validate_integers!
  validate_intervals!
  validate_booleans!
  validate_log_level!
  validate_cache_level!
end