aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/route_set.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-02 14:10:22 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-02 14:10:22 -0600
commit8db038227ca4cbcba01a86ef5fb94cb13c780463 (patch)
treeb03e34fa0800175021719994fb6f1d04488e22d3 /actionpack/lib/action_dispatch/routing/route_set.rb
parent4dee277a9bc05083de6c831cf9aae0846849ecda (diff)
downloadrails-8db038227ca4cbcba01a86ef5fb94cb13c780463.tar.gz
rails-8db038227ca4cbcba01a86ef5fb94cb13c780463.tar.bz2
rails-8db038227ca4cbcba01a86ef5fb94cb13c780463.zip
Move controller namespace tracking into route set so it gets
reloaded in dev mode
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/route_set.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb36
1 files changed, 34 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 5e9c36bbaf..201cf462e4 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -202,10 +202,11 @@ module ActionDispatch
end
end
- attr_accessor :routes, :named_routes, :configuration_files
+ attr_accessor :routes, :named_routes, :configuration_files, :controller_paths
def initialize
self.configuration_files = []
+ self.controller_paths = []
self.routes = []
self.named_routes = NamedRouteCollection.new
@@ -252,7 +253,7 @@ module ActionDispatch
def load!
# Clear the controller cache so we may discover new ones
- Routing.clear_controller_cache!
+ @controller_constraints = nil
load_routes!
end
@@ -297,6 +298,37 @@ module ActionDispatch
routes_changed_at
end
+ CONTROLLER_REGEXP = /[_a-zA-Z0-9]+/
+
+ def controller_constraints
+ @controller_constraints ||= begin
+ source = controller_namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" }
+ source << CONTROLLER_REGEXP.source
+ Regexp.compile(source.sort.reverse.join('|'))
+ end
+ end
+
+ def controller_namespaces
+ namespaces = Set.new
+
+ # Find any nested controllers already in memory
+ ActionController::Base.subclasses.each do |klass|
+ controller_name = klass.underscore
+ namespaces << controller_name.split('/')[0...-1].join('/')
+ end
+
+ # Find namespaces in controllers/ directory
+ controller_paths.each do |load_path|
+ load_path = File.expand_path(load_path)
+ Dir["#{load_path}/**/*_controller.rb"].collect do |path|
+ namespaces << File.dirname(path).sub(/#{load_path}\/?/, '')
+ end
+ end
+
+ namespaces.delete('')
+ namespaces
+ end
+
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil)
route = Route.new(app, conditions, requirements, defaults, name)
@set.add_route(*route)