TODO: Write a gem description
Add this line to your application's Gemfile:
gem 'context_validations'
And then execute:
$ bundle
Or install it yourself as:
$ gem install context_validations
This is a fun project that I started cause I needed context validations.
What you can do with it right now
class CreateUserValidator
include ContextValidations::Base
def validators
[
validates([:email, :name], :uniq),
validates(:email, :email_format),
validates(:name, :length, minimum: 4),
validates(:password, :confirm),
validates(:password, :present),
validates(:password_confirmation, :present),
validates(:password, :length, in: 6..25),
]
end
end
class User < ActiveRecord::Base
end
user = User.new(attributes)
validator = CreateUserValidator.new(user)
validator.valid?
- Fork it ( http://github.com//context_validations/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request