Elixir Drops 0.2.0 with support for custom types was released!

Since the previous release in October, my intermittent efforts have been dedicated to developing version 0.2.0 of Elixir Drops, concentrating primarily on enhancing its type system. The main objective has been to introduce the functionality for users to create custom types and to enable their composition. I’m thrilled to share that today I’ve completed the work and released Elixir Drops version 0.2.0! Let’s explore the new capabilities it brings. Defining custom types You can encapsulate validation logic in simple custom primitive types. Let’s say you want a user with age and name attributes, here’s how you could define it: ...

February 1, 2024 · 4 min · Peter Solnica

Introducing Elixir Drops

A few years ago my Ruby friends asked me if it would be possible to port some of the dry-rb libraries to Elixir. I remember some early community attempts at porting dry-validation specifically, I did my best to support the effort but back then my Elixir knowledge was too basic and I was too busy with other work. Fast forward to today and I’m happy to announce the very first release of Elixir Drops! 🎉 In this article I’ll introduce you to the concepts of the library and show you how you could use it. ...

October 25, 2023 · 5 min · Peter Solnica

Be cautious with Ruby coercion methods

Coercion is a tricky problem to solve and it’s something we need pretty much everywhere. Whether you’re building a web application or a CLI tool, you will have to coerce values in some way. I say it’s a tricky problem because Ruby comes with many builtin coercion methods but it’s not enough. Furthermore, the builtin methods may actually lead to bugs or surprising behaviors. In this article we’ll take a look at the builtin coercion methods, various caveats that come with their usage and ways how you can handle coercion in a more predictable and strict way. ...

July 29, 2020 · 5 min · Peter Solnica

Introducing dry-schema

Two years ago (!!!) I published a post on discourse.dry-rb.org explaining my plans for dry-validation 1.0.0 and in this post I mentioned that there will be a new gem called dry-schema that dry-validation will use for its schemas. It’s crazy how time flies because I swear I thought it was last year. I know that over this time dry-validation has been accumulating a lot of issues (125 in the moment of writing this article), and I know it sucks, big time, that I didn’t have a chance to address any of these. ...

January 31, 2019 · 6 min · Peter Solnica

Duck typing vs type safety in Ruby

Duck typing is one of the virtues of the Ruby language, it adds a lot of flexibility to the code, and allows us to use objects of different type in places where only specific methods are needed. Even though the idea behind duck typing may seem to be straight-forward, it is easy to use it incorrectly. It’s interesting to notice that over many years we’ve adopted various techniques that seem to leverage duck typing, but the specifics of how exactly we’re doing it are actually questionable, and I believe they deserve some reconsideration. This is directly related to the other important subject - type safety, and in this article I’d like to explain why we should care about it, while keeping duck typing in mind, too. ...

November 2, 2016 · 6 min · Peter Solnica

Invalid Object Is An Anti-Pattern

The idea of an object that validates its own state has been made very popular by Rails’ ActiveRecord. We can see this pattern in many places, not only in ORM libraries but in many other gems whenever some sort of validation is needed. Have you ever thought about why we’re allowing invalid state just to…validate data? It doesn’t seem to be a good idea, in fact, it feels like a huge anti-pattern. ...

December 28, 2015 · 4 min · Peter Solnica

Introducing dry-validation

We started experimenting with a new validation library under dry-rb organization a couple of months ago, and last month I released the first version of dry-validation. Since then I worked hard on improving it and adding support for i18n. Today, I released dry-validation 0.3.0 with a couple of bug fixes, new features and a complete support for i18n. Before I tell you what it is and how it can help you, let me start by explaining the reasoning behind this project. ...

December 7, 2015 · 8 min · Peter Solnica