dry-rb/dry-validation

import_predicates_as_macros: included_in?, format?, size? issues

Ouverte

#608 ouverte le 19 déc. 2019

 (9 commentaires) (0 réaction) (0 personne assignée)Ruby (195 forks)github user discovery
bughelp wanted

Métriques du dépôt

Stars
 (1 422 étoiles)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

class MyContract < Dry::Validation::Contract
  params do
    required(:hogwarts_house).hash do
      required(:head).filled(:string)
      required(:common_room).hash do
        required(:name).filled(:string)
        required(:location).filled(:string)
      end
    end
  end

  rule('hogwarts_house.head').validate(size?: 1..255)
  rule('hogwarts_house.head').validate(format?: SOME_REGEX)
  rule('hogwarts_house.common_room.location').validate(included_in?: ['tower', 'underground'])
end

For included_in? and size? passing an array of integers/strings not working but it works when just one value passed or with predicates which do not require arrays) included_in?

rule('hogwarts_house.common_room.location').validate(included_in?: ['tower', 'underground'])

size?

rule('hogwarts_house.head').validate(size?: 1..255) ArgumentError (wrong number of arguments (given 256, expected 2))

This predicate is just returning error. format?

rule('hogwarts_house.head').validate(format?: SOME_REGEX) Dry::Container::Error: Nothing registered with the key :format?

Guide contributeur