Skip to content

Commit

Permalink
Add auto namespacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Oct 30, 2010
1 parent 68d3c89 commit 860a940
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/sinatra/namespace.rb
Expand Up @@ -54,6 +54,10 @@ def make_namespace(mod, options = {})
options[:base] ||= self
Namespace.make_namespace(mod, options)
end

def make_namespace?(klass, meth)
true
end
end

module ModularMethods
Expand Down Expand Up @@ -89,5 +93,23 @@ def self.registered(klass)
end
end

module NamespaceDetector
Module.send(:include, self)
def method_missing(meth, *args, &block)
return super if is_a? Class or !name
base = Object
detected = name.split('::').any? do |name|
base = base.const_get(name)
base < Sinatra::Base
end
if detected and base.make_namespace?(self, meth)
Sinatra::Namespace.make_namespace self, :base => base
send(meth, *args, &block)
else
super
end
end
end

register Namespace
end

0 comments on commit 860a940

Please sign in to comment.