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

ruby-grape / grape / 30206988366 / 13
97%
master: 97%

Build:
Build:
LAST BUILD BRANCH: fix/adversarial-sweep-2026-08
DEFAULT BRANCH: master
Ran 26 Jul 2026 02:54PM UTC
Files 169
Run time 3s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

26 Jul 2026 02:52PM UTC coverage: 95.455% (+0.06%) from 95.4%
30206988366.13

Pull #2822

github

ericproulx
Add a numericality validator

Grape has no built-in way to bound or shape-check a numeric parameter
beyond `values:` (a closed inclusive range or list). Users end up
reaching for a `values:` lambda or a full `contract_scope` schema for
something as simple as "must be a positive integer" or "0..100
inclusive with an exclusive upper bound", both of which are more
ceremony than the check deserves and produce weak error messages.

Add `NumericalityValidator`, registered as `numericality`, following
ActiveModel::Validations::NumericalityValidator's option naming for
familiarity: `greater_than`, `greater_than_or_equal_to`, `less_than`,
`less_than_or_equal_to`, `equal_to`, `other_than`, `only_integer`,
`odd`, `even`. Any combination can be supplied and each has its own
i18n message key (mirroring how `length` has separate `length_min`/
`length_max`/`length_is` keys).

Design notes:
- Non-Numeric values are skipped rather than erroring — numeric-ness
  is `type:`/coercion's job; this validator only owns bounds/parity,
  so it composes with `coerce` instead of duplicating it.
- Applied to a typed array (`type: [Integer]`), every element is
  checked individually (`Array.wrap`), matching how `values` already
  treats arrays — `length` is the one that owns the array's own size.
- `only_integer` accepts whole-numbered `Float`/`BigDecimal` too
  (`val == val.to_i`), not just literal `Integer`.
- Obviously contradictory option combinations (`greater_than` +
  `greater_than_or_equal_to`, `less_than` + `less_than_or_equal_to`,
  `odd` + `even`, `equal_to` + any other comparison, or a reversed
  lower/upper bound) raise `ArgumentError` at definition time, same
  as `length_validator`'s existing `min > max` guard.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Pull Request #2822: Add a numericality validator

1144 of 1262 branches covered (90.65%)

Branch coverage included in aggregate %.

3750 of 3865 relevant lines covered (97.02%)

946.71 hits per line

Source Files on job run-3.4-gemfiles/rails_8_0.gemfile - 30206988366.13
  • Tree
  • List 169
  • Changed 0
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Build 30206988366
  • 8e72ff1f on github
  • Prev Job for on add_numericality_validator (#30166451855.20)
  • Next Job for on add_numericality_validator (#30207548041.2)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc