We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hanami::Validations::Namespace
When the validator class is defined in the module with name includes Validator, Hanami::Validations::Namespace returns unexpected value.
Validator
require 'hanami/validations' module Validators class UserValidator include Hanami::Validations messages :i18n validations do required(:name) { filled? & str? } end end end puts Validators::UserValidator.namespace.to_s #=> s.user_validator
puts Validators::UserValidator.namespace.to_s #=> validators.user
I'd like to define custom error messages for this validator, like below.
# config/locales/errors.en.yml en: errors: rules: validators: user: rules: name: filled?: "must be non empty string" str?: "must be non empty string"
https://guides.hanamirb.org/v1.3/validations/advanced-usage/#custom-namespace
require 'hanami/validations' module Validators class UserValidator include Hanami::Validations namespace :'validators/user' end end
require 'hanami/validations' module Hanami module Validations class Namespace private def name_without_suffix @name.delete_suffix(SUFFIX) end end end end module Validators class UserValidator include Hanami::Validations end end puts Validators::UserValidator.namespace.to_s #=> validators.user
Now hanami-validations gem supports Ruby >= 2.3.0, so I give up to create pull request :(
hanami-validations
The text was updated successfully, but these errors were encountered:
@epaew What's the expected value for you?
Sorry, something went wrong.
@jodosha
The namespace value I expected for Validators::UserValidator class is "validators.user".
Validators::UserValidator
"validators.user"
I updated the detail of this issue.
@jodosha is the issue still have?
jodosha
No branches or pull requests
Environments
Issue detail
When the validator class is defined in the module with name includes
Validator
,Hanami::Validations::Namespace
returns unexpected value.Expected
Motivation
I'd like to define custom error messages for this validator, like below.
How to escape
1. define namespace manually
https://guides.hanamirb.org/v1.3/validations/advanced-usage/#custom-namespace
2. apply monkey patch (for Ruby >= 2.5.0)
Now
hanami-validations
gem supports Ruby >= 2.3.0, so I give up to create pull request :(The text was updated successfully, but these errors were encountered: