Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 114 lines (99 sloc) 4.073 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
56cdc81 @wycats Remove default match without specified method
wycats authored
25 get '/rails/info/properties' => "rails/info#properties"
cb44e0f @schneems /rails/info/routes path shows routing information
schneems authored
26 get '/rails/info/routes' => "rails/info#routes"
27 get '/rails/info' => "rails/info#index"
baea5d6 @schneems Use Rails to Render Default Index Page
schneems authored
28 get '/' => "rails/welcome#index"
117daba @carllerche Update Rails' built in routes to use RouteSet#append
carllerche authored
29 end
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
30 end
31 end
32
e49f94d @josevalim Revert behavior from a5684dfa3c16472bfa5d5d861ba78cb6dbadcb59 and ensure...
josevalim authored
33 initializer :build_middleware_stack do
f816666 @josevalim Alias app to build_middleware_stack for clarity.
josevalim authored
34 build_middleware_stack
e49f94d @josevalim Revert behavior from a5684dfa3c16472bfa5d5d861ba78cb6dbadcb59 and ensure...
josevalim authored
35 end
36
820c0fe @drogus Explicitly define main_app proxy
drogus authored
37 initializer :define_main_app_helper do |app|
38 app.routes.define_mounted_helper(:main_app)
39 end
40
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and app...
josevalim authored
41 initializer :add_to_prepare_blocks do
42 config.to_prepare_blocks.each do |block|
43 ActionDispatch::Reloader.to_prepare(&block)
44 end
45 end
46
47 # This needs to happen before eager load so it happens
48 # in exactly the same point regardless of config.cache_classes
49 initializer :run_prepare_callbacks do
50 ActionDispatch::Reloader.prepare!
51 end
52
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
53 initializer :eager_load! do
e6747d8 @josevalim Allow users to choose when to eager_load the application or not.
josevalim authored
54 if config.eager_load
3afdfc3 @josevalim Expose remaining hooks to minimize the need for a Railtie based on feedb...
josevalim authored
55 ActiveSupport.run_load_hooks(:before_eager_load, self)
2801786 @josevalim Get rid of config.preload_frameworks in favor of config.eager_load_names...
josevalim authored
56 config.eager_load_namespaces.each(&:eager_load!)
351816f @josevalim Ensure that eager_load actually takes place just after the middleware st...
josevalim authored
57 end
58 end
59
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and app...
josevalim authored
60 # 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
61 initializer :finisher_hook do
62 ActiveSupport.run_load_hooks(:after_initialize, self)
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
63 end
64
0636c3c @fxn clearing autoloaded constants triggers routes reloading [Fixes #10685]
fxn authored
65 # Set routes reload after the finisher hook to ensure routes added in
66 # the hook are taken into account.
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
67 initializer :set_routes_reloader_hook do
68 reloader = routes_reloader
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
69 reloader.execute_if_updated
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
70 self.reloaders << reloader
0636c3c @fxn clearing autoloaded constants triggers routes reloading [Fixes #10685]
fxn authored
71 ActionDispatch::Reloader.to_prepare do
72 # We configure #execute rather than #execute_if_updated because if
73 # autoloaded constants are cleared we need to reload routes also in
74 # case any was used there, as in
75 #
76 # mount MailPreview => 'mail_view'
77 #
78 # This means routes are also reloaded if i18n is updated, which
79 # might not be necessary, but in order to be more precise we need
80 # some sort of reloaders dependency support, to be added.
81 reloader.execute
82 end
48bf667 @josevalim Ensure routes are loaded only after the initialization process finishes,...
josevalim authored
83 end
84
0636c3c @fxn clearing autoloaded constants triggers routes reloading [Fixes #10685]
fxn authored
85 # Set clearing dependencies after the finisher hook to ensure paths
86 # added in the hook are taken into account.
5ad7f8a @robin850 Use Ruby 1.9 Hash syntax in railties
robin850 authored
87 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
88 callback = lambda do
89 ActiveSupport::DescendantsTracker.clear
90 ActiveSupport::Dependencies.clear
91 end
92
93 if config.reload_classes_only_on_change
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
94 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
95 self.reloaders << reloader
0636c3c @fxn clearing autoloaded constants triggers routes reloading [Fixes #10685]
fxn authored
96
97 # Prepend this callback to have autoloaded constants cleared before
98 # any other possible reloading, in case they need to autoload fresh
99 # constants.
100 ActionDispatch::Reloader.to_prepare(prepend: true) do
101 # In addition to changes detected by the file watcher, if routes
102 # or i18n have been updated we also need to clear constants,
103 # that's why we run #execute rather than #execute_if_updated, this
104 # callback has to clear autoloaded constants after any update.
105 reloader.execute
106 end
693d2be @josevalim Move hooks back to initializers (we need an API that allows hooks to be ...
josevalim authored
107 else
108 ActionDispatch::Reloader.to_cleanup(&callback)
109 end
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files cha...
josevalim authored
110 end
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
111 end
112 end
f38e89c @josh Move railties/builtin into lib
josh authored
113 end
Something went wrong with that request. Please try again.