No commit activity in last 3 years
No release in over 3 years
Introduces new ActiveModel::Validations methods — validate_only and validate_except
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Optional validations for ActiveModel

This gem provides ability to exclude certain fields from validation process

Installation

You can install the gem by typing gem install optional_validations via your command line.

Or use it in your Gemfile:

gem 'optional_validations'

Usage

Example:

class User < ActiveRecord::Base
    validates_presence_of :email, :name, :address
end
user = User.new(params)     #suppose params contain only email
user.valid?                 #false

user.validate_only :email do
    user.valid?             #true
end

Thus every instance of ActiveModel::Validations now has the following methods:

  1. validate_only(*fields) — change the set of fields that are validated
  2. validate_except(*fields) — validate all fields except for specified ones

Release notes

0.1.1

Make validate_except and validate_only return the value from passed blocks

0.1.0

Please note that this release introduces a major API change.

validate_all method removed

validate_only and validate_except now expect a block to be passed and will only affect the behavior of the block. Object's validations are restored after the block is processed.