Module: Sinatra::MultiRoute
- Defined in:
- lib/sinatra/multi_route.rb
Overview
Sinatra::MultiRoute
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 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 collapse
- #delete(*args, &block) ⇒ Object
- #get(*args, &block) ⇒ Object
- #head(*args, &block) ⇒ Object
- #options(*args, &block) ⇒ Object
- #patch(*args, &block) ⇒ Object
- #post(*args, &block) ⇒ Object
- #put(*args, &block) ⇒ Object
- #route(*args, &block) ⇒ Object
Instance Method Details
#delete(*args, &block) ⇒ Object
54 |
# File 'lib/sinatra/multi_route.rb', line 54 def delete(*args, &block) super(*route_args(args), &block) end |
#get(*args, &block) ⇒ Object
55 |
# File 'lib/sinatra/multi_route.rb', line 55 def get(*args, &block) super(*route_args(args), &block) end |
#head(*args, &block) ⇒ Object
53 |
# File 'lib/sinatra/multi_route.rb', line 53 def head(*args, &block) super(*route_args(args), &block) end |
#options(*args, &block) ⇒ Object
56 |
# File 'lib/sinatra/multi_route.rb', line 56 def (*args, &block) super(*route_args(args), &block) end |
#patch(*args, &block) ⇒ Object
57 |
# File 'lib/sinatra/multi_route.rb', line 57 def patch(*args, &block) super(*route_args(args), &block) end |
#post(*args, &block) ⇒ Object
58 |
# File 'lib/sinatra/multi_route.rb', line 58 def post(*args, &block) super(*route_args(args), &block) end |
#put(*args, &block) ⇒ Object
59 |
# File 'lib/sinatra/multi_route.rb', line 59 def put(*args, &block) super(*route_args(args), &block) end |
#route(*args, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sinatra/multi_route.rb', line 61 def route(*args, &block) = 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, , &block) end end end |