dry-rb/dry-validation

Support for "validate" helper within rule blocks

Open

#679 opened on Dec 16, 2020

View on GitHub
 (6 comments) (3 reactions) (0 assignees)Ruby (193 forks)github user discovery
featurehelp wanted

Repository metrics

Stars
 (1,421 stars)
PR merge metrics
 (PR metrics pending)

Description

Support for executing predicates using validate method within rule blocks will make it much easier to apply various checks with extra conditions:

params do
  optional(:per_page).filled(:integer)
end

rule(:per_page) do
  if key?
    key.failure("must be within 0..20 range") unless validate(gt?: 0, lteq?: 20)
  end
end

See the original conversation: https://github.com/dry-rb/dry-validation/issues/678

Contributor guide