Project

validacity

0.0
No commit activity in last 3 years
No release in over 3 years
Validacity adds an extra layer of validation objects where all your validation logic can be moved to.
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

Validacity

Move validation definitions out of you models and form objects.

Usage

You can apply multiple sets of validation rules on-fly, remove any them if not needed and re-validate object against new rules afterwards.

By the way, the validation errors will be putten to the object so all your view helpers will be available to display the error list.

This approach will suitable if you need to validate different states of the same object differently. Say you're using a state machine and each state has it's own field set and the fields from the other satates shouldn't be validated at this time.

Or perhaps you just have to many constructions like validate :blablabla, presence: true in your model class and you want to get rid of it so you can focus on buisiness logic.

You can add a concern to your model so it becomes validatable:

# app/models/user.rb

class User
  include Validacity::Validatable
  validations :user_personal_data
end

Or you can add it directly to your object:

user = User.new
user.validations :user_personal_data

Generate new validation:

$ bundle exec rails g validacity:validation UserPersonalData
# app/validations/user_personal_data_validation.rb

class UserPersonalDataValidation
  validate :name, presence_of: true
  # ...a ton of different validations
end

Now let's try to validate your user object:

user = User.new

user.valid? # => false

user.name = "John"

uesr.valid? # => true

Installation

Add this line to your application's Gemfile:

gem 'validacity'

And then execute:

$ bundle

Now run the validation installation command:

$ bundle exec rails g validacity:install

And the event validation:

$ bundle exec rails g validacity:validation Event

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.