123456789_123456789_123456789_123456789_123456789_

Module: Sinatra::MultiRoute

Relationships & Source Files
Defined in: sinatra-contrib/lib/sinatra/multi_route.rb

Overview

Create multiple routes with one statement.

Usage

Use this extension to create a handler for multiple routes:

get '/foo', '/bar' do # ... end

Or for multiple verbs:

route :get, :post, '/' do # ... end

Or for multiple verbs and multiple routes:

route :get, :post, ['/foo', '/bar'] do # ... end

Or even for custom verbs:

route 'LIST', '/' do # ... end

Classic Application

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

require "sinatra"
require "sinatra/multi_route"

# Your classic application code goes here...

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/multi_route"

class MyApp < Sinatra::Base
  register Sinatra::MultiRoute

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

Instance Method Summary

Instance Method Details

#delete(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 62

def delete(*args, &block)   super(*route_args(args), &block)  end

#get(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 63

def get(*args, &block)      super(*route_args(args), &block)  end

#head(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 61

def head(*args, &block)     super(*route_args(args), &block)  end

#options(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 64

def options(*args, &block)  super(*route_args(args), &block)  end

#patch(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 65

def patch(*args, &block)    super(*route_args(args), &block)  end

#post(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 66

def post(*args, &block)     super(*route_args(args), &block)  end

#put(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 67

def put(*args, &block)      super(*route_args(args), &block)  end

#route(*args, &block)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 69

def route(*args, &block)
  options = Hash === args.last ? args.pop : {}
  routes = [*args.pop]
  args.each do |verb|
    verb = verb.to_s.upcase if Symbol === verb
    routes.each do |route|
      super(verb, route, options, &block)
    end
  end
end

#route_args(args) (private)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/multi_route.rb', line 82

def route_args(args)
  options = Hash === args.last ? args.pop : {}
  [args, options]
end