Browse files

Move controller namespace tracking into route set so it gets

reloaded in dev mode
  • Loading branch information...
1 parent 4dee277 commit 8db038227ca4cbcba01a86ef5fb94cb13c780463 @josh josh committed Dec 2, 2009
View
41 actionpack/lib/action_dispatch/routing.rb
@@ -265,51 +265,10 @@ module Routing
SEPARATORS = %w( / . ? )
HTTP_METHODS = [:get, :head, :post, :put, :delete, :options]
- CONTROLLER_REGEXP = /[_a-zA-Z0-9]+/
-
- # The root paths which may contain controller files
- mattr_accessor :controller_paths
- self.controller_paths = []
# A helper module to hold URL related helpers.
module Helpers
include ActionController::PolymorphicRoutes
end
-
- class << self
- 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 clear_controller_cache!
- @controller_constraints = nil
- end
-
- private
- 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
- end
end
end
View
2 actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
@@ -113,7 +113,7 @@ def connect(path, options = {})
end
end
- requirements[:controller] ||= Routing.controller_constraints
+ requirements[:controller] ||= @set.controller_constraints
if defaults[:controller]
defaults[:action] ||= 'index'
View
2 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -383,7 +383,7 @@ def match(*args)
constraints.reject! { |k, v| segment_keys.include?(k.to_s) }
conditions.merge!(constraints)
- requirements[:controller] ||= Routing.controller_constraints
+ requirements[:controller] ||= @set.controller_constraints
if via = options[:via]
via = Array(via).map { |m| m.to_s.upcase }
View
36 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -202,10 +202,11 @@ def formatted_#{selector}(*args) #
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 @@ def configuration_file
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 @@ def routes_changed_at
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)
View
2 railties/lib/rails/application.rb
@@ -387,7 +387,7 @@ def call(env)
initializer :initialize_routing do
next unless configuration.frameworks.include?(:action_controller)
- ActionController::Routing.controller_paths += configuration.controller_paths
+ ActionController::Routing::Routes.controller_paths += configuration.controller_paths
ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
ActionController::Routing::Routes.reload!
end

0 comments on commit 8db0382

Please sign in to comment.