dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
I've found that, at least in my specific case,
each do
schema do
#some schema here
end
end
is not equivalent to
FunSchema = Dry::Validation.Schema do
# some schema here
end
# ... another schema
each do
schema(FunSchema)
end
PredefinedSchema = Dry::Validation.Schema do
required(:audience).filled(:str?)
end
ComparisonSchema = Dry::Validation.Schema do
%i(lt gt lte gte).each do |key|
optional(key).maybe { int? | float? | time? }
end
end
ParamSchema = Dry::Validation.Schema do
required(:to) do
str? & eql?('*') | schema(PredefinedSchema) | each do
schema do
required(:name).filled(:str?)
required(:criteria).each do
str? | int? | float? | time? | schema(ComparisonSchema)
end
end
end
end
end
CriterionSchema = Dry::Validation.Schema do
required(:name).filled(:str?)
required(:criteria).each do
str? | int? | float? | time? | schema(ComparisonSchema)
end
end
ParamSchema = Dry::Validation.Schema do
required(:to) do
str? & eql?('*') | schema(PredefinedSchema) | each do
schema(CriterionSchema)
end
end
end
user_messages[:filled?, rule: :address]
returns nil not the provided custom message
oh no, the example is wrong. It should no be nested in another rules
.
en:
errors:
rules:
user:
filled?: "name cannot be blank"
rules:
address:
filled?: "You gotta tell us where you live"
should be
en:
errors:
rules:
user:
filled?: "name cannot be blank"
address:
filled?: "You gotta tell us where you live"
messages = Dry::Validation::Messages::YAML.load(['/tmp/errors.yml'])
user_messages = messages.namespaced(:user)
user_messages[:filled?, rule: :address] # => "You gotta tell us where you live"
required(:status, Status)
but that didn't seem to work
Hi. First of all thank you for great dry-rb
gems. Dry-v is awesome! :) I have a problem. I would like to build form schema where some fields are known and some other fields should be dynamically created. I thought that I use Form.with(custom_struct: custom_struct).(params)
with option
within configure
block [like here: http://dry-rb.org/gems/dry-validation/custom-validation-blocks/] but it doesn't work. I cannot use custom_struct
inside the schema definition:
Form = Dry::Validation.Form do
configure do
option :custom_struct
end
required(:name).filled(:str?)
required(:surname).filled(:str?)
optional(:custom).schema do
# error: "undefined method `each' for #<UnboundMethod:0x007f91b9978608> (NoMethodError)"
custom_struct.each do |element|
required(element.name)
end
end
end
I've found this topic [https://discuss.dry-rb.org/t/build-dry-validations-dynamically/164] in the forum but need some examples. Could you help me somehow? Thanks!
Dry::Types
as my sample library. Figured I would share here :P https://github.com/backus/yardcheck