The project is in a healthy, maintained state
ValidationInspector lists ActiveModel validation callbacks and their conditions (if/unless), including attributes and custom/proc validators.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

ValidationInspector

A simple Ruby gem to list ActiveModel validation callbacks with their conditions.

Installation

Add this line to your application's Gemfile:

gem 'validation_inspector'

And then execute:

bundle install

Usage

require 'validation_inspector'

class User < ApplicationRecord
  attr_accessor :name, :email, :age

  validates :name, presence: true, if: :active?
  validates :email, format: { with: /@/ }
  validates :age, numericality: { greater_than: 0 }
  validate :custom_validation
end

User.inspect_validations
=>
[
  { validator: ActiveModel::Validations::PresenceValidator,
    attributes: [:name],
    if_conds: [":active?"] },
  { validator: ActiveModel::Validations::FormatValidator,
    attributes: [:email],
    options: { with: "/@/" } },
  { validator: ActiveModel::Validations::NumericalityValidator,
    attributes: [:age],
    options: { greater_than: 0 } },
  { validator: :custom_validation,
    attributes: nil }
]

Note: Options from custom validators or other unsupported validators are not included in the options field.

License

The gem is available as open source under the terms of the MIT License.