No commit activity in last 3 years
No release in over 3 years
Context Validations to Rails models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 4.7
>= 0
>= 0
>= 0
 Project Readme

Context Validations

Get Started

Add this line to your application’s Gemfile:

gem 'tiny_validations'

Add TinyValidations to models you want to add this.

class User < ActiveRecord::Base
  include TinyValidations

  validates :name, :email, presence: true

  validations_when_not [:email_subscription, :upgrading_account] do |model|
    model.validates :city, :state, :country, presence: true
  end

  validations_when :upgrading_account do |model|
    model.validates_presence_of :credit_card_number
  end
end

@user = user.new(name: 'Nando Sousa', email: 'nandosousafr@gmail.com')
@user.valid?(:email_subscription)
#=> true

@user.valid?(:upgrading_account) 
#=> false

@user.credit_card = '324324-242342-2342423-232423'
@user.valid?(:upgrading_account) 
#=> true