common prefix for routes

27 views
Skip to first unread message

Geraldo Lopes de Souza

unread,
May 5, 2012, 8:42:51 PM5/5/12
to sinatrarb
Hi,

I want a common prefix for routes. Since I'm using Modular style, the
way I found is:

class MyBase < Sinatra::Base

def self.get(*args, &block)
args[0] = '/app' + args[0] if args[0].class == String
super(*args, &block)
end

end

I know that this code does not deal with routes as regular
expressions.
Do you suggest another more elegant way ?

PS: Sinatra::Namespace does'nt seem to apply given that I have many
files.
I've tried (and it doesnt work):

namespace '/app' do
use Blabla1
use Blabla2
end


Thanks in advance,

Geraldo Lopes de Souza

Jason Rogers

unread,
May 6, 2012, 4:24:14 PM5/6/12
to sina...@googlegroups.com
Why not just mount them under /app in your config.ru?

Here's what one of my configs looks like (top-module name changed to
MyFancyApp in order to protect the innocent):

*~*~*~*~*~* config.ru *~*~*~*~*~*~*~*

require 'rubygems'
require 'bundler'
Bundler.require(:default)
$:.unshift File.expand_path(File.dirname(__FILE__))

require 'my_fancy_app'

map '/admin' do
run MyFancyApp::Admin
end

map '/api/v1' do
run MyFancyApp::API::VersionOne
end

map '/api/v2' do
run MyFancyApp::API::VersionTwo
end

*~*~*~*~*~* config.ru *~*~*~*~*~*~*~*

--
Jason Rogers
> --
> You received this message because you are subscribed to the Google Groups "sinatrarb" group.
> To post to this group, send email to sina...@googlegroups.com.
> To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.
>

Geraldo Lopes de Souza

unread,
May 6, 2012, 7:03:02 PM5/6/12
to sinatrarb
Jason,

You've suggested a more elegant way !

Thanks

Geraldo Lopes de Souza
Reply all
Reply to author
Forward
0 new messages