Skip to content

Add array element type validation support#17

Merged
dogweather merged 27 commits intomasterfrom
feature/array-element-type-validation
Aug 28, 2025
Merged

Add array element type validation support#17
dogweather merged 27 commits intomasterfrom
feature/array-element-type-validation

Conversation

@dogweather
Copy link
Copy Markdown
Member

This PR adds support for validating array element types in ValidatedObject.

Key changes:

  • Enhanced TypeValidator to support element_type option for Array validation
  • Added proper TypeValidator registration with ActiveModel
  • Updated SimplifiedApi to handle the new syntax
  • Added comprehensive tests and documentation

Usage:
validates_attr :comments, type: Array, element_type: Comment, allow_nil: true

Benefits:

  • Type Safety: Ensures array elements are of the correct type
  • DRY: Avoids writing custom validators for array element types
  • Consistency: Provides a standard way to validate array elements
  • Clear Error Messages: Descriptive validation errors

All tests pass (18 examples, 0 failures). This is a backward compatible addition.

- Enhanced TypeValidator to support element_type option for Array validation
- Added validates_attr method alias for compatibility
- Updated SimplifiedApi to properly handle type: Array, element_type: Class syntax
- Added comprehensive tests for array element type validation
- Updated README with documentation and usage examples

Supports syntax: validates_attr :comments, type: Array, element_type: Comment, allow_nil: true
Validates that all array elements are of the specified type with clear error messages.
@dogweather dogweather merged commit 0995d86 into master Aug 28, 2025
4 checks passed
@dogweather dogweather deleted the feature/array-element-type-validation branch August 28, 2025 01:22
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.

1 participant