Yema
Installation
Add this line to your application's Gemfile:
gem 'yema'
And then execute:
$ bundle
Or install it yourself as:
$ gem install yema
Usage
Inline:
validator = Yema::Validator.new(params, Yema::Rule::Required.new(:title))
validator.valid?
Class:
class User
include Yema::Validations
attr_accessor :age
end
User.rules.add(Yema::Rule::StrongType.new(:age, type: Integer))
user = User.new
user.age = 3
user.valid? # => true
user.age = '3'
user.valid? # => true
user.age = 'abc'
user.valid? # => false
Virtus Integration:
class UserParam
include Yema::Virtus::Validations
attribute :age, Integer, required: true
end
user = UserParam.new(age: 2)
user.valid? # => true
user = UserParam.new(age: '2')
user.valid? # => true
user = UserParam.new(age: 'abc')
user.valid? # => false
user = UserParam.new
user.valid? # => false
Contributing
- Fork it
- 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