Challenge

Problem

Production applications rely on configuration files to manage environment-specific settings like database connections, API keys, and feature flags. This drill teaches you to parse YAML config files, validate required fields, check data types, and provide helpful error messages when configuration is invalid. You'll learn YAML parsing, hash validation, type checking, and error handling—essential skills for building reliable Ruby applications and tools.

Difficulty: Beginner

Instructions

  1. Read YAML configuration file (config.yml)
  2. Parse YAML into Ruby hash structure
  3. Validate required fields are present:
    • database.host, database.port, database.name
    • api.endpoint, api.timeout
    • features (hash with at least one boolean feature)
  4. Validate correct data types:
    • database.port must be integer
    • api.timeout must be integer
    • feature flags must be boolean (true/false)
  5. Print validation errors with specific field paths (e.g., 'Missing required field: database.host')
  6. Print success message if valid: 'Configuration valid: X settings loaded'
  7. Exit with status 1 if invalid, status 0 if valid

Files

Editable
Read-only

Hints

Hint 1

YAML.load_file(file) parses YAML and returns a hash

Hint 2

Use hash.dig('key1', 'key2') to safely access nested values

Hint 3

Check if value is nil to detect missing fields

Hint 4

value.is_a?(Integer) checks if value is an integer

Hint 5

[TrueClass, FalseClass].include?(value.class) checks for boolean

Hint 6

Split 'database.port' on '.' to get array of keys for .dig

Hint 7

Recursively count hash values: if value is hash, recurse; else count as 1

Provided Files (Read-only)

1. Valid configuration

Input:
validate_config('config.yml')
Expected Output:
Configuration valid: 8 settings loaded

2. Missing required field

Input:
validate_config('config.yml')
Expected Output:
Missing required field: database.port

3. Invalid data type for port

Input:
validate_config('config.yml')
Expected Output:
Invalid type for database.port: expected Integer, got String
+ 3 hidden test cases