Replace case-statements with dry-matchers
Gem
dry-matcher
offers very flexible and robust pattern matching API for Ruby. While the gem has many interesting use-cases I would like to focus on very specific one: Using a matcher instead of standard conditional structures likeif
orcase
.Backing Rails enums with Postgres ENUM type
Rails introduced
enum
in version 4.1. It’s a handy feature, which lets you describe any trait of an object in a very friendly and human readable way. If you need to keep track of the state of an entity, you will most likely add a field to the model and store a value there.