Sinatra validations
I use this library to validate parameters in my Sinatra applications.
It supports defaults and type coercion.
Install
$ gem "sinatra-validations"
Usage
require "sinatra/validations"
class Api < Sinatra::Base
helpers Sinatra::Validations
get "/users" do
validate params, :sort, type: String, default: "desc"
validate params, :limit, type: Integer, default: 30
validate params, :filter_by, type: String, default: nil
# ...
end
get "/users/:user" do
validate params, :user, type: String
# ...
end
end
Documentation
Read the tests.