• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-grape / grape / 23390393427

21 Mar 2026 10:40PM UTC coverage: 96.773% (-0.07%) from 96.843%
23390393427

Pull #2657

github

ericproulx
Instantiate validators at definition time

Validators are now instantiated once at route definition time and frozen,
rather than per-request via ValidatorFactory. This removes repeated object
allocation from the hot path and moves option parsing, converter building,
and message formatting into initialize.

- Remove ValidatorFactory; ParamsScope#validate instantiates validators directly
- Freeze validator instances via Base.new override (super.freeze)
- Add Grape::Util::DeepFreeze to recursively freeze Hash/Array/String options
- Freeze ParamsScope at end of initialize; cache full_path as @full_path
- Promote validate_param! to protected with NotImplementedError default
- Extract validation_error!, hash_like?, option_value, scrub helpers in Base
- Add default_message_key class macro for pre-computing exception messages
- Eager-initialize all built-in validators (coerce, default, values, regexp, etc.)
- ContractScopeValidator no longer inherits Base (standalone with freeze)
- coerce_type receives only extracted coerce keys; callers skip manual deletes
- Add DeepFreeze spec; add SameAsValidator and ExceptValuesValidator specs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pull Request #2657: Instantiate validators at definition time

1071 of 1162 branches covered (92.17%)

Branch coverage included in aggregate %.

190 of 192 new or added lines in 20 files covered. (98.96%)

3368 of 3425 relevant lines covered (98.34%)

33012.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/lib/grape/validations/validators/default_validator.rb


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc