Created
September 29, 2010 23:35
-
-
Save nu7hatch/603761 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require "rubygems" | |
require "mounter" | |
module FooApp | |
extend Mounter | |
controllers do | |
get "/foo" do | |
"Foo..." | |
end | |
get "/bar" do | |
"Bar..." | |
end | |
end | |
end | |
FooApp.mount! | |
Mounter::Application.run! |
This file contains hidden or 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
require "sinatra" | |
module Mounter | |
class Application < Sinatra::Application | |
def self.mount(mod) | |
mod.defined_controllers.each do |name, blocks| | |
blocks.each {|block| instance_eval(&block) } | |
end | |
end | |
end | |
def mount! | |
Application.mount(self) | |
end | |
def controllers(prefix=nil, opts={}, &block) | |
routes = defined_controllers[prefix||false] ||= [] | |
routes << block | |
end | |
def defined_controllers | |
@_routes ||= {} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment