This document covers the custom validators provided by the Solid Process framework for input validation. These validators extend ActiveModel's validation system and are specifically designed to work with Solid::Input and Solid::Model classes for common data validation scenarios.
For information about input definition and the validation system, see page 2.2. For details on how validation fits into the overall process execution flow, see page 3.1.
The Solid Process framework provides eight custom validators that address common validation requirements in business applications:
| Validator | Purpose | Usage |
|---|---|---|
id_validator | Validates positive integers or integer strings | validates :user_id, id: true |
uuid_validator | Validates UUID format with configurable case sensitivity | validates :session_id, uuid: true |
email_validator | Validates email address format | validates :email, email: true |
is_validator | Validates values using predicate methods | validates :status, is: :active? |
instance_of_validator | Validates exact class match | validates :config, instance_of: Hash |
kind_of_validator | Validates class or module inclusion | validates :user, kind_of: ActiveRecord::Base |
respond_to_validator | Validates presence of methods | validates :repository, respond_to: :save |
singleton_validator | Validates singleton objects | validates :logger, singleton: true |
These validators follow ActiveModel's validation conventions and integrate seamlessly with Solid::Input and Solid::Model classes through the standard validates method. They are automatically loaded when you require solid/validators.
Sources: CHANGELOG.md41-108 lib/solid/validators/uuid_validator.rb1 lib/solid/validators/email_validator.rb1
Custom Validators Inheritance Hierarchy
All custom validators extend ActiveModel::EachValidator and follow the same validation lifecycle. They can be used in any class that includes Solid::Model, including Solid::Input classes used for process input validation.
Sources: lib/solid/validators/uuid_validator.rb1 lib/solid/validators/email_validator.rb1 CHANGELOG.md41-108
The IdValidator validates that values are positive integers or strings that can be parsed as positive integers. This is commonly used for database record IDs, reference numbers, and other positive integer identifiers.
| Feature | Description | Default |
|---|---|---|
| Accepts | Positive integers or strings representing positive integers | - |
| Minimum Value | 1 (positive integers only) | - |
| String Parsing | Attempts to convert strings to integers | - |
| Blank Handling | Uses ActiveModel's blank detection | Required unless allow_nil/allow_blank |
ID Validator Flow
Sources: CHANGELOG.md42-43 lib/solid/validators/id_validator.rb1
The UuidValidator validates that string values conform to the standard UUID format (8-4-4-4-12 hexadecimal pattern). It supports both case-sensitive and case-insensitive validation modes.
| Feature | Description | Default |
|---|---|---|
| Pattern | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} | - |
| Case Sensitivity | Configurable via :case_sensitive option | true |
| Blank Handling | Uses ActiveModel's blank detection | Required unless allow_nil/allow_blank |
The UUID validator accepts the following options:
:case_sensitive (boolean) - Controls whether validation is case-sensitive (default: true):allow_nil, :allow_blank, :messageSources: lib/solid/validators/uuid_validator.rb8-18 test/solid/validators/uuid_validator_test.rb27-121
The EmailValidator validates email address format using Ruby's built-in URI::MailTo::EMAIL_REGEXP pattern, ensuring compliance with standard email formatting rules.
The validator leverages Ruby's standard library for robust email validation:
URI::MailTo::EMAIL_REGEXP for pattern matchingSources: lib/solid/validators/email_validator.rb4-10 test/solid/validators/email_validator_test.rb17-60
The IsValidator validates values by calling predicate methods on the value itself. This enables validation based on the object's own behavior rather than external pattern matching.
| Feature | Description | Example |
|---|---|---|
| Predicate Methods | Methods ending in ? that return boolean | active?, valid?, empty? |
| Multiple Predicates | Can specify array of predicates (all must pass) | is: [:active?, :verified?] |
| Dynamic Validation | Uses object's own methods for validation | validates :status, is: :active? |
Is Validator Flow
Sources: CHANGELOG.md44-45 lib/solid/validators/is_validator.rb1
The InstanceOfValidator validates that a value is exactly an instance of a specific class (not including subclasses). This provides strict type checking when inheritance should not be considered.
Sources: CHANGELOG.md103 lib/solid/validators/instance_of_validator.rb1
The KindOfValidator validates that a value is an instance of a class or includes a module (including subclasses and mixed-in modules). This provides flexible type checking with inheritance support.
Sources: CHANGELOG.md104 lib/solid/validators/kind_of_validator.rb1
The RespondToValidator validates that a value responds to specified method(s). This enables duck-typing validation where objects must provide specific interfaces.
Sources: CHANGELOG.md106 lib/solid/validators/respond_to_validator.rb1
The SingletonValidator validates that a value is a singleton object (an instance of a class where instance_of? returns true for the class itself). This is useful for validating singleton pattern implementations or class objects.
Sources: CHANGELOG.md107 lib/solid/validators/singleton_validator.rb1
Both validators integrate with Solid::Input classes through ActiveModel's validation framework, supporting standard validation options and error handling patterns.
| Pattern | Example | Description |
|---|---|---|
| Required Field | validates :email, email: true | Field must be present and valid |
| Optional Field | validates :email, email: true, allow_nil: true | Field can be nil but must be valid if present |
| Blank Allowed | validates :email, email: true, allow_blank: true | Field can be blank but must be valid if not blank |
Both validators produce standard ActiveModel error messages:
:blank - "can't be blank" (when value is blank and not allowed):invalid - "is invalid" (when value doesn't match expected format)Sources: test/solid/validators/uuid_validator_test.rb7-25 test/solid/validators/email_validator_test.rb7-15
Refresh this wiki