Yema

Build Status Code Climate

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

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