diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-02-20 12:04:57 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-02-20 12:04:57 -0600 |
commit | 69c049f5ab45bf9bfb0d269acea0773581905fd4 (patch) | |
tree | f605c68ba9fae9ddfa77115ad0cef0da5a8ce770 /actionpack/lib | |
parent | 53fe301a42f9d18b4a8a475e9babf64c621369ae (diff) | |
download | rails-69c049f5ab45bf9bfb0d269acea0773581905fd4.tar.gz rails-69c049f5ab45bf9bfb0d269acea0773581905fd4.tar.bz2 rails-69c049f5ab45bf9bfb0d269acea0773581905fd4.zip |
Move development mode reloading up the stack to avoid issues with class reloading in middleware
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/dispatcher.rb | 41 | ||||
-rw-r--r-- | actionpack/lib/action_controller/reloader.rb | 14 |
3 files changed, 42 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 1a3e05cc86..ca826e7bfc 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -59,6 +59,7 @@ module ActionController autoload :ParamsParser, 'action_controller/params_parser' autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes' autoload :RecordIdentifier, 'action_controller/record_identifier' + autoload :Reloader, 'action_controller/reloader' autoload :Request, 'action_controller/request' autoload :RequestForgeryProtection, 'action_controller/request_forgery_protection' autoload :Rescue, 'action_controller/rescue' diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index e91babde10..ec40b5c4e6 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -5,8 +5,9 @@ module ActionController class << self def define_dispatcher_callbacks(cache_classes) unless cache_classes - # Development mode callbacks - before_dispatch :reload_application + unless self.middleware.include?(Reloader) + self.middleware.insert_after(Failsafe, Reloader) + end ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false end @@ -41,6 +42,30 @@ module ActionController callback = ActiveSupport::Callbacks::Callback.new(:prepare_dispatch, block, :identifier => identifier) @prepare_dispatch_callbacks.replace_or_append!(callback) end + + def run_prepare_callbacks + if defined?(Rails) && Rails.logger + logger = Rails.logger + else + logger = Logger.new($stderr) + end + + new(logger).send :run_callbacks, :prepare_dispatch + end + + def reload_application + # Run prepare callbacks before every request in development mode + run_prepare_callbacks + + Routing::Routes.reload + end + + def cleanup_application + # Cleanup the application before processing the current request. + ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord) + ActiveSupport::Dependencies.clear + ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord) + end end cattr_accessor :middleware @@ -87,18 +112,6 @@ module ActionController dispatch end - def reload_application - # Cleanup the application before processing the current request. - ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord) - ActiveSupport::Dependencies.clear - ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord) - - # Run prepare callbacks before every request in development mode - run_callbacks :prepare_dispatch - - Routing::Routes.reload - end - def flush_logger Base.logger.flush end diff --git a/actionpack/lib/action_controller/reloader.rb b/actionpack/lib/action_controller/reloader.rb new file mode 100644 index 0000000000..46789309cd --- /dev/null +++ b/actionpack/lib/action_controller/reloader.rb @@ -0,0 +1,14 @@ +module ActionController + class Reloader + def initialize(app) + @app = app + end + + def call(env) + Dispatcher.reload_application + @app.call(env) + ensure + Dispatcher.cleanup_application + end + end +end |