Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR brings a common way to load parsers, formatters, validators and middleware versioners. With this change, it facilitates the customization through inheritance.
Parsers, formatters and error formatters
Parsers, formatters and error formatters had static constant named
DEFAULTSthat was acting as a lookup to translate a format (:json, :xml, etc ...) to an actual class. Instead of relying on this, it will now use a dynamic registryGrape::Util::Registrythat will be warmed up through inheritance like the validators (Seebaseclasses) Thus,zeitwerk, eager loads classes, so the registries are filled up when Grape is required.Versioners
I applied the same pattern for middleware versioners since its translating a symbol to an actual class.
Validators
For the validators, I've just replace the actual registry by
Grape::Util::Registryand I removed theconst_getpart since all validators are eager loaded.Contract scope
I moved the contract scope validator to the
validatorsfolders and rename it toContractScopeValidatorto have a better short name thanvalidator.Grape::Util::Registry
#2437 introduced a
lengthvalidator and users that already have one with the same name might not be aware that its been overridden. Giving the situation, the registry will emit a warning if an entry has changed. This is true for all classes that are using the registry.DryTypeCoercer
I've refactored the part where its was calling
const_getto use a static array.