This extension is part of the Sinatra::Contrib project. Run gem install sinatra-contrib to have it available.

Sinatra::Decompile

Sinatra::Decompile is an extension that provides a method, conveniently called decompile, that will generate a String pattern for a given route.

Usage

Classic Application

To use the extension in a classic application all you need to do is require it:

require "sinatra"
require "sinatra/decompile"

# Your classic application code goes here...

This will add the decompile method to the application/class scope, but you can also call it as Sinatra::Decompile.decompile.

Modular Application

To use the extension in a modular application you need to require it, and then, tell the application you will use it:

require "sinatra/base"
require "sinatra/decompile"

class MyApp < Sinatra::Base
  register Sinatra::Decompile

  # The rest of your modular application code goes here...
end

This will add the decompile method to the application/class scope. You can choose not to register the extension, but instead of calling decompile, you will need to call Sinatra::Decompile.decompile.

Fork me on GitHub