postrank-labs/goliath — pull request #112 by mikelewis (2011-12-11 06:24:51+00:00)
Title: Added CoerceValue validation

Often times I find myself doing something like params['something'].to_i, and even type checking before that. This validation middleware coerces the given params element to the given coerce type. An example of this would be:

use Goliath::Rack::Validation::CoerceValue, {:key => 'user_id', :as => :integer}

`params['user_id']` would now be an integer assuming `params['user_id']` was originally `"{integer}"`. If it was something other than an integer, it would call validation_error ( or set to a default value if it was given).

It currently supports integers, booleans, strings and JSON objects.