dry-schema

v1.14
  1. Introduction
  2. Basics
    1. Built-in predicates
    2. Macros
    3. Type specs
    4. Working with schemas
  3. Optional keys and values
  4. Nested data
  5. Reusing schemas
  6. Params
  7. JSON
  8. Error messages
  9. Advanced
    1. Composing schemas
    2. Custom predicates
    3. Custom types
    4. Filtering
    5. Key maps
    6. Predicate logic
    7. Processor steps
    8. Rule AST
    9. Unexpected keys
  10. Extensions
    1. Hints
    2. Info
    3. JSON Schema
    4. Monads

TOC

  1. Learn more

Custom predicates

If you want to define custom predicates, you can create a special module that includes default ones along with your custom functions:

module MyPredicates
  include Dry::Logic::Predicates

  def self.future_date?(date)
    date > Date.today
  end
end

Then you can configure it as your default predicates module:

Schema = Dry::Schema.Params do
  config.predicates = MyPredicates

  required(:release_date).value(:date, :future_date?)
end

Notice that you need to provide custom error messages for your own predicates.

Learn more