Digget
This gem aims to make for an easier search API by validating incoming parameters and filtering your model accordingly.
Note: this gem is under very early development and is not finished in any way
Usage
Validating of parameters
The only thing you have to do is extends the Validator class, so you can use the verify method.
class YourValidator < Digget::Validator
def validate_id_params
verify :id, Integer, max: 100, min: 50
end
def validate_search_params
verify :name, String, required: true
verify :size, Float, required: true, min: 15
end
endTo validate the params you need to run the validator;
validator = YourValidator.new(params)
validator.validate_id_paramsYou can then see if there are any errors during validation
validator.errorsYou can also get a Hash with the parameters casted to the right datatype;
validator.casted_paramsSupported datatypes
- Float
- Integer
- String
- Date
- Time
Supported validation options
All of the following options can be combined
- required (checks whether the parameter is present)
- min (checks whether the parameter is larger than the provided value)
- max (checks whether the parameter is lower than the provided value)
- min_length (checks whether the parameter is longer than this)
- max_length (checks whether the parameter is shorter than this)
- length (checks whether the parameter has this exact length)
- equal (check whether the parameter is equal to the provided value)
- not_equal (checks whether the parameter is not equal to the provided value)
Installation
Add this line to your application's Gemfile:
gem 'digget'And then execute:
$ bundleOr install it yourself as:
$ gem install diggetLicense
The gem is available as open source under the terms of the MIT License.