# This module allows you to prepend a version prefix to your Sinatra URLs
# Example:
#
# require 'rubygems'
# require 'sinatra/base'
#
# class App < Sinatra::Base
# register Versioned
#
# set :version, 'v1'
#
# # => GET /v1/hello
# get '/hello' do
# 'This is a GET for version' + options.version.inspect
# end
#
# # => POST /v1/hello
# post '/hello' do
# 'This is a POST for version ' + options.version.inspect
# end
#
# end
module Versioned
def post(*args, &block)
super *versioned_route(args), &block
end
def get(*args, &block)
super *versioned_route(args), &block
end
def put(*args, &block)
super *versioned_route(args), &block
end
def delete(*args, &block)
super *versioned_route(args), &block
end
protected
def versioned_route(args)
args[0] = "/#{version}#{args[0]}"
args
end
end