No commit activity in last 3 years
No release in over 3 years
With this gem you will have several validations that are common on day day and that will make life much easier for dev. Validations can be returned in a simple and standardized way..
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0
 Project Readme

ValidationContract

Gem Version ruby Build Status Build Status Maintainability Dependency Status

This gem and its validations have been implemented on top of the Notification Pattern, which allows API to return all the validations at a single time, improving the user experience.

Validations of the day day for your rails project.

With this gem you will have several validations that are common on day day and that will make life much easier for dev. Validations can be returned in a simple and standardized way.

Installation

Add this line to your application's Gemfile:

gem 'validation_contract'

And then execute:

bundle

Or install it yourself as:

gem install validation_contract

Usage

require 'validation_contract'

validation_contract = ValidationContract::Validations.new

Verifying an invalid email, the return will be an array with message and its validation inside, this will occur for all the desired validations.

validation_contract.is_email('teste.com', 'This email is invalid') => "{message: 'This email is invalid'}"

By checking a valid email, nothing will be added in the return, leaving only the validations that are with incorrect values.

validation_contract.is_email('teste@teste.com', 'This email is invalid') => "nil"

Suggestion for the validations. Perform all the necessary validations and then before executing the desired process use the following:

if !validation_contract.is_valid
    return validation_contract.errros
end

This will check if there is any invalid field, if there is an arry returned with all the validations. This type of validation is very good for APIs that are being used for a form with many fields, so you return to the FRONT all errors at one time.

Validations

Validation Example Done
required validate if field is required V
has_min_len check if the field has a minimum of characters V
has_max_len checks if the field has a maximum of characters V
fixed_len checks if there is an x quantity of V
email check if email is valid V
greater_than valid if one number is greater than another V
lower_than valid if one number is smaller than another V
errors Return errors V
clear Clears the arry error V
valid Check whether this arry is valid or not V
url check if url is valid V

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributor

Ricardo Grassi.

Alan Lira.

License

ValidationContract is released under the MIT License.