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 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 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
62 |
# File 'lib/sinatra/multi_route.rb', line 62 def delete(*args, &block) super(*route_args(args), &block) end |
#get(*args, &block) ⇒ Object
63 |
# File 'lib/sinatra/multi_route.rb', line 63 def get(*args, &block) super(*route_args(args), &block) end |
#head(*args, &block) ⇒ Object
61 |
# File 'lib/sinatra/multi_route.rb', line 61 def head(*args, &block) super(*route_args(args), &block) end |
#options(*args, &block) ⇒ Object
64 |
# File 'lib/sinatra/multi_route.rb', line 64 def (*args, &block) super(*route_args(args), &block) end |
#patch(*args, &block) ⇒ Object
65 |
# File 'lib/sinatra/multi_route.rb', line 65 def patch(*args, &block) super(*route_args(args), &block) end |
#post(*args, &block) ⇒ Object
66 |
# File 'lib/sinatra/multi_route.rb', line 66 def post(*args, &block) super(*route_args(args), &block) end |
#put(*args, &block) ⇒ Object
67 |
# File 'lib/sinatra/multi_route.rb', line 67 def put(*args, &block) super(*route_args(args), &block) end |
#route(*args, &block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sinatra/multi_route.rb', line 69 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 |