A Roda plugin which symbolizes request params
Ruby
Switch branches/tags
Nothing to show
Clone or download
Latest commit ab1d67c Apr 21, 2015
Permalink
Failed to load latest commit information.
bin Initial commit Apr 21, 2015
lib/roda/plugins Initial commit Apr 21, 2015
spec Initial commit Apr 21, 2015
.gitignore Initial commit Apr 21, 2015
.travis.yml Initial commit Apr 21, 2015
Gemfile Initial commit Apr 21, 2015
LICENSE.txt Initial commit Apr 21, 2015
README.md Initial commit Apr 21, 2015
Rakefile Initial commit Apr 21, 2015
roda-symbolized_params.gemspec Initial commit Apr 21, 2015

README.md

Roda::SymbolizedParams

A Roda plugin that exposes symbolized request params.

Installation

gem 'roda-symbolized_params'

Usage

require "roda"

class App < Roda
  plugin :symbolized_params

  route do |r|
    r.root do
      params[:foo] # symbolized request params
    end
  end
end

This plugin exposes the #params method which is just a wrapper around request.params, but with symbolized keys.

This plugin is similar to the built-in indifferent_params plugin, but with real symbolized keys. Advantage of this plugin is that you don't have to always keep in mind that you still actually have string keys, so you can normally use methods like Hash#fetch, and you can use params as keyword arguments.

An obvious disadvantage is that new symbols are created each time, which have to be garbage collected. So you shouldn't use this plugin in Ruby versions < 2.2.0, because Ruby Symbol GC was only introduced in Ruby 2.2.0.

License

MIT