No commit activity in last 3 years
No release in over 3 years
A quick and simple way to set defaults for the params helper on a per route basis.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.3
 Project Readme

Sinatra Default Parameters

Build status

Master branch: Build Status

Develop branch: Build Status

What?

A quick and simple way to set defaults for the params helper on a per route basis.

Why?

I was inspired to make this into a gem after answering this question on StackOverflow. I liked the look of it and thought I'll use this again, hence a gem.

How?

It's quite simple.

require 'sinatra/default_parameters'

helpers Sinatra::DefaultParameters # This too if you're using modular style apps.

get "/" do
  set_defaults a: 1, b: 2, c: 3
  params.inspect
end

# GET "/"
# => {"a"=>1, "b"=>2, "c"=>3}
# GET "/?a=7&b=4"
# => {"a"=>"7", "b"=>"4", "c"=>3}
# GET "/?d=4"
# => {"a"=>1, "b"=>2, "c"=>3, "d"=>"4"}
# GET "/?a=7&b=4&d=4"
# => {"a"=>"7", "b"=>"4", "c"=>3, "d"=>"4"}

Simples, innit.

Note: As you can see from the examples it doesn't do any type casting or other checks, it just does this one very small thing, the rest is up to you.

Licence

See the LICENCE file.