Validation library with type-safe schemas and rules
MIT License
Bot releases are visible (Hide)
This release is a complete rewrite on top of dry-schema
that uses contract classes to define schema and validation rules. It's not backward-compatible. This release addressed over 150 known issues, including bugs and missing features.
See the list of all addressed issues as well as issues that were moved to dry-schema and addressed there.
Dry::Validation::Contract
API for defining contract classes with schemas and validation ruleskey
and base
messages, and arbitrary meta-data (like error codes etc.)rule(:items).each { ... }
:acceptance
macroValidation.register_macro
for registering global macros (solnic)Contract.register_macro
for registering macros available to specific contract classes (solnic)Dry::Validation.Contract
shortcut for quickly defining a contract and getting its instance back (solnic)config.locale
for setting the default locale (solnic)config/errors.yml
are now bundled with the gem, rc2
was broken because of this (solnic)Published by solnic over 5 years ago
This was yanked on rubygems.org because the bundled gem was missing config
directory, thus it was not possible to require it. It was fixed in rc3
.
Dry::Validation::Macros.register(:your_macro, &block)
(solnic):acceptance
as the first built-in macro (issue #157) (solnic)failure
will raise a meaningful error instead of crashing (solnic)values
is now an instance of a hash-like Dry::Validation::Values
class, rather than Dry::Schema::Result
. This gives more convenient access to data within rules (solnic)dry-schema
was updated to ~> 1.0
(solnic):hints
extension is back (solnic)Result
objects have access to the context object which is shared between rules (flash-gordon)Contract#inspect
no longer crashes (solnic)dry-schema
was bumped to ~> 0.6
- this pulls in dry-types 1.0.0
and dry-logic 1.0.0
(solnic)dry-initializer
was bumped to ~> 3.0
(solnic)Published by solnic over 5 years ago
Support for arbitrary meta-data in failures, ie:
class NewUserContract < Dry::Validation::Contract
params do
required(:login).filled(:string)
end
rule(:login) do
key.failure(text: 'is taken', code: 123) unless db.unique?(values[:login])
end
end
Now your error hash will include { login: [{ text: 'is taken', code: 123 }] }
(solnic + flash-gordon)
Error
was renamed to Message
as it is a more generic concept (solnic)ErrorSet
was renamed to MessageSet
for consistency (solnic):monads
extension wraps entire result objects in Success
or Failure
(flash-gordon)Published by solnic over 5 years ago
base.failure
for base errors and key.failure
for key errors (solnic)base
errors associated with a key even when child keys have errors too (solnic)base
errors not associated with any key (solnic)ErrorSet
object now for managing messages (solnic)locale
and full
options now (solnic)top_namespace
for messages, which will be used for both schema and rule localization (solnic)Result#errors
returns an instance of ErrorSet
now, it's an enumerable, coerible to a hash (solnic)failure
was removed in favor of key.failure
or key(:foo).failure
(solnic)Result#to_hash
was removed (flash-gordon)dry-types
was locked to ~> 0.14.0
(flash-gordon)The first round of bug fixes. Thanks for testing <3!
errors.rule.%{key}
too, but a message under nested key will override it (solnic)Complete rewrite on top of dry-schema
.
Dry::Validation::Contract
as a replacement for validation schemas (solnic)rule
DSL with an improved API for setting error messages (solnic)~> 0.4.2
(flash-gordon)dry-types
0.13.1 and dry-struct
0.5.0, these are now minimal supported versions (flash-gordon)Form
was renamed to Params
to be consistent with the latest changes from dry-types
. You can require 'dry/validation/compat/form'
to use the previous names but it will be removed in the next version (flash-gordon)Published by solnic over 7 years ago