Coder Social home page Coder Social logo

rdy / validation_reflection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redinger/validation_reflection

1.0 1.0 0.0 106 KB

This plugin adds reflective access to validations

Home Page: http://rubygems.org/gems/validation_reflection

License: MIT License

validation_reflection's Introduction

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.

validation_reflection's People

Contributors

redinger avatar grimen avatar sutto avatar duritong avatar skoppensboer avatar

Stargazers

Ryan Dy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.