Skip to content

Conversation

@danielnottingham
Copy link
Owner

@danielnottingham danielnottingham commented Dec 15, 2025

Description

This PR introduces the ArrayValidator class to enable comprehensive validation of array collections. It addresses the need for validating list structures, including size constraints, uniqueness, and nested element validation, filling a gap in the library's capabilities.

Fixes # (issue)
#5

New ValidatorRb::ArrayValidator Class:

  • Implemented validators for size: min_items, max_items, length, non_empty.
  • Implemented validators for content: unique, contains (aliased as includes).
  • Implemented nested validation: of(validator) allows validating each element against another validator schema.
  • Implemented transformations: compact (removes nils) and flatten (flattens nested arrays).

Updated ValidatorRb Module:

  • Added ValidatorRb.array entry point for easy instantiation.

Documentation & Examples:

  • Updated README.md with comprehensive usage examples for array validation.
  • Updated CHANGELOG.md to reflect the new feature.
    Added examples/array_validation.rb script demonstrating various use cases.
    Example Usage:
# Basic usage with size and uniqueness constraints
validator = ValidatorRb.array.min_items(2).max_items(5).unique
result = validator.validate([1, 2, 3])

# Validating an array of emails (Nested Validation)
email_validator = ValidatorRb.string.email
array_validator = ValidatorRb.array.of(email_validator)

emails = ["valid@example.com", "invalid-email", "another@example.com"]
result = array_validator.validate(emails)
# Errors will contain path information (e.g., index of invalid element)

@danielnottingham danielnottingham self-assigned this Dec 15, 2025
@danielnottingham danielnottingham changed the title Feat: Implement ArrayValidator for Collection Validation feat: Implement ArrayValidator for Collection Validation Dec 15, 2025
@danielnottingham danielnottingham merged commit 87b5a6e into main Dec 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants