From e962d492fb4511818e4e2a7d1cef8e527338cef4 Mon Sep 17 00:00:00 2001 From: Tim Hwang Date: Mon, 21 Oct 2024 13:09:07 -0700 Subject: [PATCH] update README with instructions on sum types I had to look into specs to discover that this behavior was supported: https://github.com/dry-rb/dry-schema/blob/main/spec/integration/params/macros/value_spec.rb#L31 I feel this is a very useful pattern, and that making it more discoverable will be more user-friendly. --- docsite/source/basics/macros.html.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docsite/source/basics/macros.html.md b/docsite/source/basics/macros.html.md index e6f5560b..dde4af69 100644 --- a/docsite/source/basics/macros.html.md +++ b/docsite/source/basics/macros.html.md @@ -19,6 +19,15 @@ Dry::Schema.Params do end ``` +Predicates passed as an array will be `OR`-ed automatically: + +```ruby +Dry::Schema.Params do + # expands to `required(:id) { str? | int? }` + required(:id).value([:string, :integer]) +end +``` + ### filled Use it when a value is expected to be filled. "filled" means that the value is non-nil and, in the case of a `String`, `Hash`, or `Array` value, that the value is not `.empty?`.