ActiveValidators
<img src=“https://badge.fury.io/rb/active_validators.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/nepalez/active_validators.svg” alt=“Build Status” /> <img src=“https://codeclimate.com/github/nepalez/active_validators.png” /> <img src=“https://gemnasium.com/nepalez/active_validators.svg” alt=“Dependency Status” /> <img src=“https://coveralls.io/repos/nepalez/active_validators/badge.png” alt=“Coverage Status” />
The plugin provides additional validators for ActiveRecord models.
DateValidator
Checks the date is after|before|not after|not before another date.
validates :next_birthday, date: { after: Time.now, not_after: 1.year.from_now }
Use the :allow_nil
key to skip validation in case the attribute value isn’t set.
validates :next_birthday, date: { after: Time.now, allow_nil: true }
Error messages are translated with a corresponding keys (in a same way as in the Rails Guide):
-
after_date
-
before_date
-
not_after_date
-
not_before_date
TimeValidator
Checks the time is after|before|not after|not before given time (in seconds).
validates :next_alarm, time: { after: Time.now, not_after: 1.day.from_now }
Use the :allow_nil
key to skip validation in case the attribute value isn’t set.
validates :next_alarm, time: { after: Time.now, allow_nil: true }
Error messages are translated with a corresponding keys (in a same way as in the Rails Guide):
-
after_time
-
before_time
-
not_after_time
-
not_before_time
NotEqualsValidator
Checks if a value not equals to another attibute’s value.
validates :finish, not_equals: { to: :start }
Use the :allow_nil
key to skip validation in case the attribute value isn’t set.
validates :finish, not_equals: { to: :start, allow_nil: true }
Error message is translated with a :not_equals
key.
Installation
Add string to your Gemfile:
gem "active_validators"
Version changes
See the CHANGELOG.
License
This project rocks and uses MIT-LICENSE.