Sha256: 743a850cc1840458f50518d8b0af888a01787ebdf5a1bab66f6c73ad82ab3048
Contents?: true
Size: 934 Bytes
Versions: 3
Compression:
Stored size: 934 Bytes
Contents
--- title: Constraints layout: gem-single name: dry-types --- You can create constrained types that will use validation rules to check that the input is not violating any of the configured constraints. You can treat it as a lower level guarantee that you're not instantiating objects that are broken. All types support the constraints API, but not all constraints are suitable for a particular primitive, it's up to you to set up constraints that make sense. Under the hood it uses [`dry-logic`](/gems/dry-logic) and all of its predicates are supported. ``` ruby string = Types::String.constrained(min_size: 3) string['foo'] # => "foo" string['fo'] # => Dry::Types::ConstraintError: "fo" violates constraints email = Types::String.constrained( format: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i ) email["jane@doe.org"] # => "jane@doe.org" email["jane"] # => Dry::Types::ConstraintError: "jane" violates constraints ```
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-types-1.2.2 | docsite/source/constraints.html.md |
dry-types-1.2.1 | docsite/source/constraints.html.md |
dry-types-1.2.0 | docsite/source/constraints.html.md |