-
-
Save dctanner/184480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This module allows you to prepend a verion 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment