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. Return true if valid, false if invalid

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

Ruby 3.4

Provided Files (Read-only)

1. Valid configuration

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

2. Returns true for valid config

Input:
result = validate_config('config.yml')
puts result
Expected Output:
Configuration valid: 13 settings loaded
true

3. Detects all required fields

Input:
validate_config('config.yml')
puts 'Validation complete'
Expected Output:
Configuration valid: 13 settings loaded
Validation complete
+ 2 hidden test cases