facebook Clutch Top custom software development companies

About dry-schema Ruby gem in details

About dry-schema Ruby gem in details
Average rating: 3
(1 votes)

Thanks! You’ve rated this material!

We just presented you 40 most used Ruby gems that can be very helpful for you. And today we are going to discuss the validation of the structure and basic checks, which is meant to ensure that given data input is safe to work with. So, yes, today’s post will be about dry-schema Ruby gem in details.

The sole purpose of dry-schema is to process and validate data input. There are many use cases for this library, most common ones are checking HTTP parameters (either GET or POST) and JSON data structures. If you’re familiar with dry-validation, it’s the same thing but without complex features like high-level rules or complex predicates.

When you apply a schema 4 things happen:

  1. Known keys are coerced, if needed, to symbols, unknown keys are rejected
  2. (optional) Before trying to apply coercion, values can be checked using pre-coercion rules
  3. Values are coerced, when needed, based on the type specifications in the schema
  4. Keys and values are validated based on rules defined in the schema

When you apply a schema, keys are always processed.

What it means is that unknown keys are always rejected. In case of Params and JSON schemas, keys are also coerced to symbols. This is handled by a separate step now, that used a new KeyMap object. There will be more features built on top of it, like producing error messages about unexpected keys (something that was requested many times before).

Interested? Feel free to check more here.

And let’s explore together ValueSemantics, that is a Ruby gem for making value classes.

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111