aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-14 17:54:41 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-14 17:54:41 -0600
commit5f8e48cbd297aca4add4b48efa2136ba6ac851b1 (patch)
tree939c7670965015dc0721967204d2c533f597ae46 /actionpack/lib
parentce970a8bb9f124d19d28270b1ffc8c4532bbbcc1 (diff)
downloadrails-5f8e48cbd297aca4add4b48efa2136ba6ac851b1.tar.gz
rails-5f8e48cbd297aca4add4b48efa2136ba6ac851b1.tar.bz2
rails-5f8e48cbd297aca4add4b48efa2136ba6ac851b1.zip
Move route reloading into railties
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/dispatch/dispatcher.rb5
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb109
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/routing.rb2
3 files changed, 21 insertions, 95 deletions
diff --git a/actionpack/lib/action_controller/dispatch/dispatcher.rb b/actionpack/lib/action_controller/dispatch/dispatcher.rb
index e04da42637..cf02757cf6 100644
--- a/actionpack/lib/action_controller/dispatch/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatch/dispatcher.rb
@@ -13,11 +13,6 @@ module ActionController
# Run prepare callbacks before every request in development mode
self.prepare_each_request = true
- # Development mode callbacks
- ActionDispatch::Callbacks.before_dispatch do |app|
- ActionController::Routing::Routes.reload
- end
-
ActionDispatch::Callbacks.after_dispatch do
# Cleanup the application before processing the current request.
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 6f35e9b4e3..bf2443c1be 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -203,23 +203,18 @@ module ActionDispatch
end
end
- attr_accessor :routes, :named_routes, :configuration_files, :controller_paths
+ attr_accessor :routes, :named_routes
+ attr_accessor :disable_clear_and_finalize
def initialize
- self.configuration_files = []
- self.controller_paths = []
-
self.routes = []
self.named_routes = NamedRouteCollection.new
- @clear_before_draw = true
- @finalize_set_on_draw = true
-
- clear!
+ @disable_clear_and_finalize = false
end
def draw(&block)
- clear! if @clear_before_draw
+ clear! unless @disable_clear_and_finalize
mapper = Mapper.new(self)
if block.arity == 1
@@ -228,16 +223,20 @@ module ActionDispatch
mapper.instance_exec(&block)
end
- if @finalize_set_on_draw
- @set.add_route(NotFound)
- install_helpers
- @set.freeze
- end
+ finalize! unless @disable_clear_and_finalize
nil
end
+ def finalize!
+ @set.add_route(NotFound)
+ install_helpers
+ @set.freeze
+ end
+
def clear!
+ # Clear the controller cache so we may discover new ones
+ @controller_constraints = nil
routes.clear
named_routes.clear
@set = ::Rack::Mount::RouteSet.new(:parameters_key => PARAMETERS_KEY)
@@ -252,75 +251,6 @@ module ActionDispatch
routes.empty?
end
- def add_configuration_file(path)
- self.configuration_files << path
- end
-
- # Deprecated accessor
- def configuration_file=(path)
- add_configuration_file(path)
- end
-
- # Deprecated accessor
- def configuration_file
- configuration_files
- end
-
- def load!
- # Clear the controller cache so we may discover new ones
- @controller_constraints = nil
-
- load_routes!
- end
-
- # reload! will always force a reload whereas load checks the timestamp first
- alias reload! load!
-
- def reload
- if configuration_files.any? && @routes_last_modified
- if routes_changed_at == @routes_last_modified
- return # routes didn't change, don't reload
- else
- @routes_last_modified = routes_changed_at
- end
- end
-
- load!
- end
-
- def load_routes!
- if configuration_files.any?
- @finalize_set_on_draw = false
- configuration_files.each_with_index do |config, index|
- @finalize_set_on_draw = true if index == (configuration_files.length - 1)
- load(config)
- @clear_before_draw = false if index == 0
- end
- @clear_before_draw = true
- @finalize_set_on_draw = true
-
- @routes_last_modified = routes_changed_at
- else
- draw do |map|
- map.connect ":controller/:action/:id"
- end
- end
- end
-
- def routes_changed_at
- routes_changed_at = nil
-
- configuration_files.each do |config|
- config_changed_at = File.stat(config).mtime
-
- if routes_changed_at.nil? || config_changed_at > routes_changed_at
- routes_changed_at = config_changed_at
- end
- end
-
- routes_changed_at
- end
-
CONTROLLER_REGEXP = /[_a-zA-Z0-9]+/
def controller_constraints
@@ -340,11 +270,14 @@ module ActionDispatch
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}\/?/, '')
+ # TODO: Move this into Railties
+ if defined?(Rails.application)
+ # Find namespaces in controllers/ directory
+ Rails.application.configuration.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
end
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
index 794fb888b7..fc477afb17 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -46,7 +46,6 @@ module ActionDispatch
request_method = nil
end
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
request = recognized_request_for(path, request_method)
expected_options = expected_options.clone
@@ -80,7 +79,6 @@ module ActionDispatch
def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
expected_path = "/#{expected_path}" unless expected_path[0] == ?/
# Load routes.rb if it hasn't been loaded.
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
generated_path, extra_keys = ActionController::Routing::Routes.generate_extras(options, defaults)
found_extras = options.reject {|k, v| ! extra_keys.include? k}