aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/middleware/callbacks.rb2
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb15
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb28
3 files changed, 10 insertions, 35 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb
index d07841218a..7cf75ffe63 100644
--- a/actionpack/lib/action_dispatch/middleware/callbacks.rb
+++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb
@@ -37,7 +37,7 @@ module ActionDispatch
def initialize(app, prepare_each_request = false)
@app, @prepare_each_request = app, prepare_each_request
- run_callbacks(:prepare)
+ run_callbacks(:prepare) unless @prepare_each_request
end
def call(env)
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index e4bd143e78..335daafc01 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -3,24 +3,13 @@ require "rails"
module ActionDispatch
class Railtie < Rails::Railtie
- plugin_name :action_dispatch
+ railtie_name :action_dispatch
# Prepare dispatcher callbacks and run 'prepare' callbacks
initializer "action_dispatch.prepare_dispatcher" do |app|
# TODO: This used to say unless defined?(Dispatcher). Find out why and fix.
require 'rails/dispatcher'
-
- unless app.config.cache_classes
- # Setup dev mode route reloading
- routes_last_modified = app.routes_changed_at
- reload_routes = lambda do
- unless app.routes_changed_at == routes_last_modified
- routes_last_modified = app.routes_changed_at
- app.reload_routes!
- end
- end
- ActionDispatch::Callbacks.before { |callbacks| reload_routes.call }
- end
+ ActionDispatch::Callbacks.to_prepare { app.routes_reloader.reload_if_changed }
end
end
end \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 660d28dbec..c49ac70562 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -222,19 +222,18 @@ module ActionDispatch
end
end
- attr_accessor :routes, :named_routes
- attr_accessor :disable_clear_and_finalize
+ attr_accessor :routes, :named_routes, :controller_namespaces
+ attr_accessor :disable_clear_and_finalize, :resources_path_names
def self.default_resources_path_names
{ :new => 'new', :edit => 'edit' }
end
- attr_accessor :resources_path_names
-
def initialize
self.routes = []
self.named_routes = NamedRouteCollection.new
- self.resources_path_names = self.class.default_resources_path_names
+ self.resources_path_names = self.class.default_resources_path_names.dup
+ self.controller_namespaces = Set.new
@disable_clear_and_finalize = false
end
@@ -281,32 +280,19 @@ module ActionDispatch
def controller_constraints
@controller_constraints ||= begin
- source = controller_namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" }
+ namespaces = controller_namespaces + in_memory_controller_namespaces
+ source = namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" }
source << CONTROLLER_REGEXP.source
Regexp.compile(source.sort.reverse.join('|'))
end
end
- def controller_namespaces
+ def in_memory_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
-
- # TODO: Move this into Railties
- if defined?(Rails.application)
- # Find namespaces in controllers/ directory
- Rails.application.config.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
-
namespaces.delete('')
namespaces
end