2010-01-23 10:07:20 -05:00
|
|
|
module Rails
|
|
|
|
class Application
|
|
|
|
module Finisher
|
|
|
|
include Initializable
|
|
|
|
|
2010-04-05 04:52:47 -04:00
|
|
|
initializer :add_generator_templates do
|
2010-10-06 11:18:59 -04:00
|
|
|
config.generators.templates.unshift(*paths["lib/templates"].existent)
|
2010-04-05 04:52:47 -04:00
|
|
|
end
|
|
|
|
|
2010-06-22 17:17:20 -04:00
|
|
|
initializer :ensure_autoload_once_paths_as_subset do
|
|
|
|
extra = ActiveSupport::Dependencies.autoload_once_paths -
|
|
|
|
ActiveSupport::Dependencies.autoload_paths
|
2010-01-23 11:13:25 -05:00
|
|
|
|
|
|
|
unless extra.empty?
|
|
|
|
abort <<-end_error
|
2010-06-22 17:17:20 -04:00
|
|
|
autoload_once_paths must be a subset of the autoload_paths.
|
|
|
|
Extra items in autoload_once_paths: #{extra * ','}
|
2010-01-23 11:13:25 -05:00
|
|
|
end_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-27 11:39:35 -05:00
|
|
|
initializer :add_builtin_route do |app|
|
2010-01-23 10:07:20 -05:00
|
|
|
if Rails.env.development?
|
2010-09-17 15:27:48 -04:00
|
|
|
app.routes.append do
|
2012-04-24 23:32:09 -04:00
|
|
|
get '/rails/info/properties' => "rails/info#properties"
|
2012-05-22 19:23:17 -04:00
|
|
|
get '/rails/info/routes' => "rails/info#routes"
|
|
|
|
get '/rails/info' => "rails/info#index"
|
2010-09-17 15:27:48 -04:00
|
|
|
end
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-19 02:02:28 -05:00
|
|
|
initializer :build_middleware_stack do
|
2010-06-20 19:08:50 -04:00
|
|
|
build_middleware_stack
|
2010-02-19 02:02:28 -05:00
|
|
|
end
|
|
|
|
|
2011-04-25 08:56:58 -04:00
|
|
|
initializer :define_main_app_helper do |app|
|
|
|
|
app.routes.define_mounted_helper(:main_app)
|
|
|
|
end
|
|
|
|
|
2011-12-12 09:18:19 -05:00
|
|
|
initializer :add_to_prepare_blocks do
|
|
|
|
config.to_prepare_blocks.each do |block|
|
|
|
|
ActionDispatch::Reloader.to_prepare(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This needs to happen before eager load so it happens
|
|
|
|
# in exactly the same point regardless of config.cache_classes
|
|
|
|
initializer :run_prepare_callbacks do
|
|
|
|
ActionDispatch::Reloader.prepare!
|
|
|
|
end
|
|
|
|
|
2010-05-15 17:48:56 -04:00
|
|
|
initializer :eager_load! do
|
2012-08-01 09:07:01 -04:00
|
|
|
if config.eager_load
|
2010-05-15 18:34:54 -04:00
|
|
|
ActiveSupport.run_load_hooks(:before_eager_load, self)
|
2010-06-01 18:42:20 -04:00
|
|
|
eager_load!
|
2010-05-15 17:48:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-12 09:18:19 -05:00
|
|
|
# All initialization is done, including eager loading in production
|
2010-05-15 17:48:56 -04:00
|
|
|
initializer :finisher_hook do
|
|
|
|
ActiveSupport.run_load_hooks(:after_initialize, self)
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
|
2011-12-12 09:18:19 -05:00
|
|
|
# Set app reload just after the finisher hook to ensure
|
|
|
|
# routes added in the hook are still loaded.
|
2011-12-13 03:25:12 -05:00
|
|
|
initializer :set_routes_reloader_hook do
|
|
|
|
reloader = routes_reloader
|
2011-12-13 05:23:21 -05:00
|
|
|
reloader.execute_if_updated
|
2011-12-13 03:25:12 -05:00
|
|
|
self.reloaders << reloader
|
2011-12-13 05:23:21 -05:00
|
|
|
ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated }
|
2010-09-02 06:54:16 -04:00
|
|
|
end
|
|
|
|
|
2011-12-12 16:51:33 -05:00
|
|
|
# Set app reload just after the finisher hook to ensure
|
|
|
|
# paths added in the hook are still loaded.
|
2011-12-15 12:48:10 -05:00
|
|
|
initializer :set_clear_dependencies_hook, :group => :all do
|
2011-12-13 03:25:12 -05:00
|
|
|
callback = lambda do
|
|
|
|
ActiveSupport::DescendantsTracker.clear
|
|
|
|
ActiveSupport::Dependencies.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
if config.reload_classes_only_on_change
|
2011-12-13 05:23:21 -05:00
|
|
|
reloader = config.file_watcher.new(*watchable_args, &callback)
|
2011-12-13 03:25:12 -05:00
|
|
|
self.reloaders << reloader
|
|
|
|
# We need to set a to_prepare callback regardless of the reloader result, i.e.
|
|
|
|
# models should be reloaded if any of the reloaders (i18n, routes) were updated.
|
2011-12-13 04:07:02 -05:00
|
|
|
ActionDispatch::Reloader.to_prepare(:prepend => true){ reloader.execute }
|
2011-12-13 03:25:12 -05:00
|
|
|
else
|
|
|
|
ActionDispatch::Reloader.to_cleanup(&callback)
|
|
|
|
end
|
2011-12-12 16:51:33 -05:00
|
|
|
end
|
|
|
|
|
2010-01-23 10:07:20 -05:00
|
|
|
# Disable dependency loading during request cycle
|
2010-01-25 18:08:08 -05:00
|
|
|
initializer :disable_dependency_loading do
|
2012-08-01 09:07:01 -04:00
|
|
|
if config.eager_load
|
2010-01-23 10:07:20 -05:00
|
|
|
ActiveSupport::Dependencies.unhook!
|
|
|
|
end
|
|
|
|
end
|
2012-04-27 00:38:08 -04:00
|
|
|
|
|
|
|
initializer :activate_queue_consumer do |app|
|
2012-04-28 03:26:23 -04:00
|
|
|
if config.queue == Rails::Queueing::Queue
|
2012-05-02 23:10:27 -04:00
|
|
|
app.queue_consumer = config.queue_consumer.start(app.queue)
|
|
|
|
at_exit { app.queue_consumer.shutdown }
|
2012-04-27 00:38:08 -04:00
|
|
|
end
|
|
|
|
end
|
2010-01-23 10:07:20 -05:00
|
|
|
end
|
|
|
|
end
|
2010-03-20 13:34:21 -04:00
|
|
|
end
|