Repository is archived
No commit activity in last 3 years
No release in over 3 years
provides a simple way to validate hashes(params, json etc)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Simple validator that validates hashes

I needed a simple validation utility that i can use to validate params, json etc. So i am creating one.

  1. It should provide an easy way to add additional validations

     module Validation
       module Rules
         def my_custom_validation(field, message='')
           callback = lambda do | data |
             if data[field] == something_special
               true
             else
               false
             end
           end
           validates(field, callback, message)
         end
       end
     end
    
  2. It can reuse defined validations when defining one

     module Validation
       module Rules
         def validates_numericality_of(field, message='')
           validates_presence_of(field)
           validates_format_of(field, /^\d+(\.\d+)?$/
         end
       end
     end
    
  3. It should provide some predefined validations

  • validates_presence_of - checks if the field is present and it is not nil or empty string
  • validates_confirmation_of - checks if a field is confirmed by checking filed_confirmation value
  • validates_format_of - checks if a field is in a given format
  • validates_numericality_of - checks if a field is a correct number format
  • validates_greather_then - checks if a field is greather then some value
  • validates_less_then - checks if a field is less then some value
  • validates_length_of_within - checks if the length is in some bounds
  • validates_option_in - checks if the field is one of allowed options

For additional info check the specs for usage validates simple specs

License: MIT

Gem Version