New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validate blocks raise an exception about missing messages #168
Labels
Comments
I'm needing to use the |
@ThisIsMissEm I can't reproduce the problem, as the validations context doesn't respond to # frozen_string_literal: true
require "bundler/setup"
require "hanami/validations"
require "hanami/validations/form"
module EmailPredicate
include Hanami::Validations::Predicates
self.messages_path = "./errors.yml"
predicate(:email?) do |current|
current.match(/@/)
end
end
class PropertyValidator
include Hanami::Validations::Form
validations do
end
end
class MyValidator
include Hanami::Validations::Form
predicates EmailPredicate
validations do
optional(:Properties).maybe(:hash?)
validate(valid_properties: :Properties) do |rooms|
rooms.all? do |_key, value|
PropertyValidator.new(value).valid?
end
end
end
end
params = {}
PropertyValidator.new(params).validate.success?
MyValidator.new(params).validate.success?
__END__
ruby test.rb
Traceback (most recent call last):
19: from test.rb:41:in `<main>'
18: from /Users/luca/.gem/ruby/2.6.3/gems/hanami-validations-1.3.3/lib/hanami/validations.rb:365:in `validate'
17: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/schema.rb:72:in `call'
16: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:83:in `call'
15: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:83:in `reduce'
14: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:83:in `each'
13: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:85:in `block in call'
12: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:46:in `call'
11: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:46:in `each_with_object'
10: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:46:in `each'
9: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:47:in `block in call'
8: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:47:in `each'
7: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/executor.rb:48:in `block (2 levels) in call'
6: from /Users/luca/.gem/ruby/2.6.3/gems/dry-validation-0.11.2/lib/dry/validation/schema_compiler.rb:14:in `call'
5: from /Users/luca/.gem/ruby/2.6.3/gems/dry-logic-0.4.2/lib/dry/logic/operations/check.rb:33:in `call'
4: from /Users/luca/.gem/ruby/2.6.3/gems/dry-logic-0.4.2/lib/dry/logic/rule.rb:47:in `call'
3: from /Users/luca/.gem/ruby/2.6.3/gems/dry-logic-0.4.2/lib/dry/logic/rule.rb:51:in `[]'
2: from /Users/luca/.gem/ruby/2.6.3/gems/dry-logic-0.4.2/lib/dry/logic/rule.rb:69:in `block in bind'
1: from /Users/luca/.gem/ruby/2.6.3/gems/dry-logic-0.4.2/lib/dry/logic/rule.rb:69:in `instance_exec'
test.rb:33:in `block (2 levels) in <class:MyValidator>': undefined local variable or method `properties' for #<#<Class:0x00007f88b59d7a98>:0x00007f88b68c17c0> (NameError) |
Closing due to lack of feedback. If this is still an issue, please provide an update so we can re-open this issue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I've the following code:
Then else where I do: (there's a bit of additional abstraction, but it seems to not be important)
This then triggers the following error:
I've tried setting
messages_path
, and various other combinations of things that I've found between the Hanami::Validations and Dry::Validations READMEs and docs, but nothing seems to resolve this error.What do I need to do in order to use the
validate
method in myvalidations
block?The text was updated successfully, but these errors were encountered: