Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 172 lines (145 sloc) 4.724 kB
6690d66 @josevalim Rename config.cookie_secret to config.secret_token and pass it as con…
josevalim authored
1 require 'active_support/core_ext/hash/reverse_merge'
02c5137 @josevalim Add view paths to Engine setup.
josevalim authored
2 require 'fileutils'
b17e358 @josevalim Move configuration to subfolders.
josevalim authored
3 require 'rails/plugin'
2fde9d7 @josevalim Solve some pendencies.
josevalim authored
4 require 'rails/engine'
dc677f7 tests pass with requiring the frameworks in rails.rb
Carlhuda authored
5
accd9b4 @josh Restore "Start Rails::Application object
josh authored
6 module Rails
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
7 # In Rails 3.0, a Rails::Application object was introduced which is nothing more than
8 # an Engine but with the responsibility of coordinating the whole boot process.
9 #
10 # Opposite to Rails::Engine, you can only have one Rails::Application instance
11 # in your process and both Rails::Application and YourApplication::Application
12 # points to it.
13 #
14 # In other words, Rails::Application is Singleton and whenever you are accessing
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored
15 # Rails::Application.config or YourApplication::Application.config, you are actually
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
16 # accessing YourApplication::Application.instance.config.
17 #
18 # == Initialization
19 #
20 # Rails::Application is responsible for executing all railties, engines and plugin
21 # initializers. Besides, it also executed some bootstrap initializers (check
22 # Rails::Application::Bootstrap) and finishing initializers, after all the others
23 # are executed (check Rails::Application::Finisher).
24 #
25 # == Configuration
26 #
27 # Besides providing the same configuration as Rails::Engine and Rails::Railtie,
28 # the application object has several specific configurations, for example
29 # "allow_concurrency", "cache_classes", "consider_all_requests_local", "filter_parameters",
30 # "logger", "metals", "reload_engines", "reload_plugins" and so forth.
31 #
32 # Check Rails::Application::Configuration to see them all.
33 #
34 # == Routes
35 #
36 # The application object is also responsible for holding the routes and reloading routes
37 # whenever the files change in development.
38 #
39 # == Middlewares and metals
40 #
41 # The Application is also responsible for building the middleware stack and setting up
42 # both application and engines metals.
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored
43 #
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
44 class Application < Engine
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
45 autoload :Bootstrap, 'rails/application/bootstrap'
f8bf198 @josevalim Add tests for explicit engines.
josevalim authored
46 autoload :Configurable, 'rails/application/configurable'
b17e358 @josevalim Move configuration to subfolders.
josevalim authored
47 autoload :Configuration, 'rails/application/configuration'
4f03603 @josevalim Break application.rb file in smaller chunks.
josevalim authored
48 autoload :Finisher, 'rails/application/finisher'
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configu…
josevalim authored
49 autoload :MetalLoader, 'rails/application/metal_loader'
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
50 autoload :Railties, 'rails/application/railties'
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
51 autoload :RoutesReloader, 'rails/application/routes_reloader'
52
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
53 class << self
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
54 private :new
79b0b50 @wycats Aliasing class_eval makes JRuby ornery.
wycats authored
55
56 def configure(&block)
57 class_eval(&block)
58 end
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
59
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
60 def instance
db99324 @josevalim Ensure calling a method in Rails::Application does not instantiate a …
josevalim authored
61 if self == Rails::Application
62 Rails.application
9212652 @josh Add Rails::Application pointer to the default app to add symmetry to …
josh authored
63 else
db99324 @josevalim Ensure calling a method in Rails::Application does not instantiate a …
josevalim authored
64 @@instance ||= new
9212652 @josh Add Rails::Application pointer to the default app to add symmetry to …
josh authored
65 end
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
66 end
67
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
68 def inherited(base)
2fde9d7 @josevalim Solve some pendencies.
josevalim authored
69 raise "You cannot have more than one Rails::Application" if Rails.application
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
70 super
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
71 Rails.application = base.instance
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored
72
73 ActiveSupport.run_load_hooks(:before_configuration, base.instance)
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
74 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
75
e7418ab @josevalim Add more tests to some key points in Railties.
josevalim authored
76 def respond_to?(*args)
77 super || instance.respond_to?(*args)
78 end
79
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
80 protected
81
82 def method_missing(*args, &block)
83 instance.send(*args, &block)
426348b @josh Update routes.rb template to use App name
josh authored
84 end
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
85 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
86
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored
87 delegate :middleware, :metal_loader, :to => :config
395d664 @josevalim Move application configuration to the application configuration objec…
josevalim authored
88
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
89 def require_environment!
1b816d5 @josevalim The rake task :environment now loads config/environment.rb instead of…
josevalim authored
90 environment = paths.config.environment.to_a.first
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
91 require environment if environment
d982fe2 Replace reopening the class with App.configure as an alias to class_eval
Carlhuda authored
92 end
93
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
94 def routes
9a5be2e Get Railties tests passing
Carlhuda authored
95 @routes ||= ActionDispatch::Routing::RouteSet.new
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
96 end
97
98 def railties
99 @railties ||= Railties.new(config)
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
100 end
5f8e48c @josh Move route reloading into railties
josh authored
101
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
102 def routes_reloader
226d8e7 @josevalim Refactor MetalLoader and RoutesReloader to rely less on class configu…
josevalim authored
103 @routes_reloader ||= RoutesReloader.new
5f8e48c @josh Move route reloading into railties
josh authored
104 end
105
106 def reload_routes!
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
107 routes_reloader.reload!
108 end
5f8e48c @josh Move route reloading into railties
josh authored
109
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
110 def initialize!
111 run_initializers(self)
112 self
5f8e48c @josh Move route reloading into railties
josh authored
113 end
114
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
115 def load_tasks
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
116 initialize_tasks
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
117 railties.all { |r| r.load_tasks }
e461e1b @josevalim Ensure application rake tasks and generators are loaded after the one…
josevalim authored
118 super
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
119 self
94bb331 @jeremy Shift more responsibility from application class to its singleton ins…
jeremy authored
120 end
121
4ca9765 @josevalim Allow railties to specify generators paths.
josevalim authored
122 def load_generators
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
123 initialize_generators
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
124 railties.all { |r| r.load_generators }
e461e1b @josevalim Ensure application rake tasks and generators are loaded after the one…
josevalim authored
125 super
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
126 self
82b9b15 Refactor plugins
Yehuda Katz + Carl Lerche authored
127 end
128
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
129 def app
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored
130 @app ||= config.middleware.build(routes)
603d4fb @josh Build middleware stack and reload routes after app initializers run
josh authored
131 end
132
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
133 def call(env)
6690d66 @josevalim Rename config.cookie_secret to config.secret_token and pass it as con…
josevalim authored
134 app.call(env.reverse_merge!(env_defaults))
135 end
136
137 def env_defaults
138 @env_defaults ||= {
139 "action_dispatch.parameter_filter" => config.filter_parameters,
140 "action_dispatch.secret_token" => config.secret_token
141 }
6d6ae08 Start moving the initializers into the application object
Carl Lerche authored
142 end
143
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
144 def initializers
5d07869 @josevalim Ensure all initializers are collections.
josevalim authored
145 initializers = Bootstrap.initializers_for(self)
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
146 railties.all { |r| initializers += r.initializers }
2d1f9fb @josh Plugins need to load before app initializers
josh authored
147 initializers += super
5d07869 @josevalim Ensure all initializers are collections.
josevalim authored
148 initializers += Finisher.initializers_for(self)
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
149 initializers
150 end
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
151
152 protected
153
154 def initialize_tasks
155 require "rails/tasks"
156 task :environment do
157 $rails_rake_task = true
1b816d5 @josevalim The rake task :environment now loads config/environment.rb instead of…
josevalim authored
158 require_environment!
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
159 end
160 end
161
162 def initialize_generators
163 require "rails/generators"
164 end
165
166 # Application is always reloadable when config.cache_classes is false.
167 def reloadable?(app)
168 true
169 end
accd9b4 @josh Restore "Start Rails::Application object
josh authored
170 end
171 end
Something went wrong with that request. Please try again.