This library provides external validations for any Ruby class.

It originates from emmanuels aequitas repository with the following changes:

  • Only support for external validators
  • Use composable algebra for internals
  • Will allow serialization to javascript for client side validation (not implemented)
  • No contextual validators anymore (use additional external validators)
  • Use dkubb/equalizer and dkubb/adamantium where possible.

Once these changes are mature they will hopefully be accepted and used as the base for a release.

Specifying Validations

require 'aequitas'

class ProgrammingLanguage
  attr_reader :name

  def initialize(name)
    @name = name

  validates_presence_of :name

ruby ='ruby')

result =
result.valid? # => true
result.violations # => #<Set: {}>

other ='')

result =
result.valid? # => false
result.violations # => #<Set: {<Aequitas:::Violation ....>}>

See Aequitas::Macros to learn about the complete collection of validation rules available.


Aequitas validations may be manually evaluated against a resource using the #valid? method, which will return true if the resource is valid, and false if it is invalid.


Working with Validation Errors

If an instance fails one or more validation rules, Aequitas::Violation instances will populate the Aequitas::ViolationSet object that is available through the #errors method.

For example:

result = => "Jose"))
if result.valid?
  # my_account is valid and can be saved
  result.violations.each do |e|
    puts e

See Aequitas::ViolationSet for all you can do with the #errors method.

Contextual Validation

Aequitas does not provide a means of grouping your validations into contexts. Define a validator per context for this.