Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 99 lines (84 sloc) 3.3 kb
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
1 module Rails
2 class Application
3 module Finisher
4 include Initializable
5
6690d66 @josevalim Rename config.cookie_secret to config.secret_token and pass it as config...
josevalim authored
6 initializer :add_generator_templates do
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely on m...
josevalim authored
7 config.generators.templates.unshift(*paths["lib/templates"].existent)
6690d66 @josevalim Rename config.cookie_secret to config.secret_token and pass it as config...
josevalim authored
8 end
9
6f83a50 @fxn renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
10 initializer :ensure_autoload_once_paths_as_subset do
11 extra = ActiveSupport::Dependencies.autoload_once_paths -
12 ActiveSupport::Dependencies.autoload_paths
924fa08 @josevalim First steps into making Plugin < Engine.
josevalim authored
13
14 unless extra.empty?
15 abort <<-end_error
6f83a50 @fxn renames load_(once_)paths to autoload_(once_)paths in dependencies and c...
fxn authored
16 autoload_once_paths must be a subset of the autoload_paths.
17 Extra items in autoload_once_paths: #{extra * ','}
924fa08 @josevalim First steps into making Plugin < Engine.
josevalim authored
18 end_error
19 end
20 end
21
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configurat...
josevalim authored
22 initializer :add_builtin_route do |app|
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
23 if Rails.env.development?
117daba @carllerche Update Rails' built in routes to use RouteSet#append
carllerche authored
24 app.routes.append do
25 match '/rails/info/properties' => "rails/info#properties"
26 end
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
27 end
28 end
29
e49f94d @josevalim Revert behavior from a5684dfa3c16472bfa5d5d861ba78cb6dbadcb59 and ensure...
josevalim authored
30 initializer :build_middleware_stack do
f816666 @josevalim Alias app to build_middleware_stack for clarity.
josevalim authored
31 build_middleware_stack
e49f94d @josevalim Revert behavior from a5684dfa3c16472bfa5d5d861ba78cb6dbadcb59 and ensure...
josevalim authored
32 end
33
820c0fe @drogus Explicitly define main_app proxy
drogus authored
34 initializer :define_main_app_helper do |app|
35 app.routes.define_mounted_helper(:main_app)
36 end
37
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and app...
josevalim authored
38 initializer :add_to_prepare_blocks do
39 config.to_prepare_blocks.each do |block|
40 ActionDispatch::Reloader.to_prepare(&block)
41 end
42 end
43
44 # This needs to happen before eager load so it happens
45 # in exactly the same point regardless of config.cache_classes
46 initializer :run_prepare_callbacks do
47 ActionDispatch::Reloader.prepare!
48 end
49
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
50 initializer :eager_load! do
9ab2904 @jviney Fix `$rails_rake_task` global variable warning without replacing the val...
jviney authored
51 if config.cache_classes && !(defined?($rails_rake_task) && $rails_rake_task)
3afdfc3 @josevalim Expose remaining hooks to minimize the need for a Railtie based on feedb...
josevalim authored
52 ActiveSupport.run_load_hooks(:before_eager_load, self)
5a0d73f @josevalim Add lib to load paths when application is inherited to be able to load l...
josevalim authored
53 eager_load!
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
54 end
55 end
56
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and app...
josevalim authored
57 # All initialization is done, including eager loading in production
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
58 initializer :finisher_hook do
59 ActiveSupport.run_load_hooks(:after_initialize, self)
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
60 end
61
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and app...
josevalim authored
62 # Set app reload just after the finisher hook to ensure
63 # routes added in the hook are still loaded.
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
64 initializer :set_routes_reloader_hook do
65 reloader = routes_reloader
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
66 reloader.execute_if_updated
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
67 self.reloaders << reloader
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
68 ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated }
48bf667 @josevalim Ensure routes are loaded only after the initialization process finishes,...
josevalim authored
69 end
70
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files cha...
josevalim authored
71 # Set app reload just after the finisher hook to ensure
72 # paths added in the hook are still loaded.
283a087 @josevalim Clean up the cache before the request in case we are running in the relo...
josevalim authored
73 initializer :set_clear_dependencies_hook, :group => :all do
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
74 callback = lambda do
75 ActiveSupport::DescendantsTracker.clear
76 ActiveSupport::Dependencies.clear
77 end
78
79 if config.reload_classes_only_on_change
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
80 reloader = config.file_watcher.new(*watchable_args, &callback)
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
81 self.reloaders << reloader
82 # We need to set a to_prepare callback regardless of the reloader result, i.e.
83 # models should be reloaded if any of the reloaders (i18n, routes) were updated.
1f5b9bb @josevalim Clean up FileUpdateChecker API.
josevalim authored
84 ActionDispatch::Reloader.to_prepare(:prepend => true){ reloader.execute }
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
85 else
86 ActionDispatch::Reloader.to_cleanup(&callback)
87 end
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files cha...
josevalim authored
88 end
89
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
90 # Disable dependency loading during request cycle
5d07869 @josevalim Ensure all initializers are collections.
josevalim authored
91 initializer :disable_dependency_loading do
92 if config.cache_classes && !config.dependency_loading
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
93 ActiveSupport::Dependencies.unhook!
94 end
95 end
96 end
97 end
f38e89c @josh Move railties/builtin into lib
josh authored
98 end
Something went wrong with that request. Please try again.