Project

digget

0.0
No commit activity in last 3 years
No release in over 3 years
Digget makes creating search endpoints easier. It allows you to put some validations on incoming parameters and use these parameters to filter models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 5.0.6
 Project Readme

codecov Build Status Codacy Badge Gem Version

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
end

To validate the params you need to run the validator;

validator = YourValidator.new(params)
validator.validate_id_params

You can then see if there are any errors during validation

validator.errors

You can also get a Hash with the parameters casted to the right datatype;

validator.casted_params

Supported 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:

$ bundle

Or install it yourself as:

$ gem install digget

License

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