Ruby libraries supporting DDD
Rdm: the missing dependencies manager for Ruby apps
With RDM you can split up one big Ruby application into multiple lightweight packages with explicit dependencies. You can do it before going the microservices
road, because this would be a much smoother transition. Going from explicit dependencies graph to proper SOA / microservices is also more straightforward. In DDD it helps to define clearer Bounded Contexts, where each package can only access explicit dependencies. Contrast this with a monolithic Rails application with one global Ruby memory space, and you might understand the benefit of having stricter, more explicit way of managing dependencies.
SmartIoC: a declarative dependency Injection library
SmartIoC is a smart and really simple IoC container for Ruby applications.
It allows you to create your dependencies on demand, supports lazy-loading of Ruby files, also allows different contexts for each dependency, so you get test/lightweight implementations in development / tests enviroments. It works great in combination with Rdm
.
HashCast - Hash attributes caster in declarative way
In the DDD context it helps to convert user input to a properly casted Ruby object / hash. It is a lightweight dependency-free Ruby library, with a nice DSL for for specifying the structure of expected input with Ruby types.
PureValidator - Ruby domain object validation library
PureValidator is a simple, mostly dependency-free (except i18n
) library to validate your domain Ruby objects. It is an excellent companion to HashCast to validate your Ruby objects against specific domain rules. What makes PureValidator special is the separation of validation rules from the object to validate. After countless fights against one-size-fits-all ActiveModel::Validations
-style validations that mix domain/value object with its valudations, we came to prefer this simpler and more flexible approach.
This approach is more popular in functional programming and leads to maintainable, easily unit-testable code. You are free to use multiple different validators for the same object in different situations. For example your validation rules during creation of an object are different from validations when user is changing a single boolean flag on it.
Contracts - Contracts for Ruby
Contracts let you clearly – even beautifully – express how your code behaves, and free you from writing tons of boilerplate, defensive code.
We have a forked version of contracts
with nice diff output for KeywordArgs type (Hash).
Active Serializer - a simple objects to hash serializer.
ActiveSerializer is a lightweight dependency-free objects serializer with a nice declarative DSL.
In our Serializers performance benchmark it places on a solid middle ground right after plain Ruby presenters while sporting a declarative DSL, providing you the same convenience as ActiveModel Serializers
do.
Compared to ActiveModel::Serializers
-dependencies (activemodel / actionpack), that move with the corresponding Rails version, you get non of the potential headaches of conflicting transient dependencies, that are the horror and bane of many biggish Rails applications.
ApiView - Friggin’ fast Serializer gem
- ApiView
Another lightweight dependency-free objects serializer. Its
DSL
is less involved, because its main focus is performance.
ApiView
is currently the fastest known Ruby-based object serializer. If you are generating huge JSON payloads in your Ruby application, it will bring you 5-10X fold performance improvements, as demonstrated in our Serializers performance benchmark.
Values - Values is a tiny library for creating value objects in ruby.
- Constructors require expected arguments
- Instances are immutable