Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

validation_reflection

> 编程语言
Open source

This plugin adds reflective access to validations

297 stars0 likes1 views
WebsiteGitHub

About

This plugin adds reflective access to validations

Validation Reflection

Version 1.0.0, 2010-10-08

This plugin adds reflective access to validations

  • ModelClass.reflect_on_all_validations
  • ModelClass.reflect_on_validations_for(:property)

Both of these methods return arrays containing instances of ActiveRecord::Reflection::MacroReflection. For example

class Person true end

refl = Person.reflect_on_validations_for(:name) refl[0].macro

=> :validates_presence_of

refl = Person.reflect_on_validations_for(:size) refl[0].macro

=> :validates_numericality_of

refl[0].options

=> { :only_integer => true }

== Customization

Usually, all the standard Rails validations are reflected. You can change this -- add or remove validations -- in an application-specific initializer,

config/initializers/validation_reflection.rb

In that file change config.reflected_validations to suit your needs. Say, you have a custom validation for email addresses, validates_as_email, then you could add it like this

config.reflected_validations :validates_as_email, :ignore_subvalidations => true }

You have to make sure that all reflected validations are defined before this plugin is loaded. To this end, you may have to explicitly set the load order of plugins somewhere in the environment configuration using

config.plugins = [...]

== Special Thanks

To Michael Schuerig, [email protected] for his initial concept and implementation of this plugin.

== License

ValidationReflection uses the MIT license. Please check the LICENSE file for more details.

Issues· 5 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言