GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - redinger/validation_reflection: This plugin adds reflective access to validations

BranchesTags
Open more actions menu

Latest commit

 

History

54 Commits
54 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
rails
rails
 
 
test
test
 
 
.gitignore
.gitignore
 
 
CHANGELOG
CHANGELOG
 
 
MIT-LICENSE
MIT-LICENSE
 
 
README
README
 
 
Rakefile
Rakefile
 
 
VERSION.yml
VERSION.yml
 
 
validation_reflection.gemspec
validation_reflection.gemspec
 
 

Repository files navigation

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 < ActiveRecord::Base
    validates_presence_of :name
    validates_numericality_of :size, :only_integer => 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

If validates_as_email is implemented in terms of other validation
methods, these validations are added to the reflection metadata,
too. As that may not be what you want, you can disable reflection
for these subordinate validations

  config.reflected_validations << {
  	:method => :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.

About

This plugin adds reflective access to validations

rubygems.org/gems/validation_reflection

Resources

Readme
MIT license
Activity

Stars

297 stars

Watchers

1 watching

Forks

16 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.