Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upvalidate blocks raise an exception about missing messages #168
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) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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
validatemethod in myvalidationsblock?