Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 519 lines (455 sloc) 18.004 kB
02c5137 @josevalim Add view paths to Engine setup.
josevalim authored
1 require 'fileutils'
8d901b9 @rafaelfranca Require yaml before trying to rescue its exception class
rafaelfranca authored
2 require 'yaml'
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
3 require 'active_support/core_ext/hash/keys'
274a3aa @trevorturk Allow transparent upgrading of legacy signed cookies to encrypted coo…
trevorturk authored
4 require 'active_support/core_ext/object/blank'
60609bb @spastorino Sign cookies using key deriver
spastorino authored
5 require 'active_support/key_generator'
0a2d004 @rafaelfranca Add missing require
rafaelfranca authored
6 require 'active_support/message_verifier'
2fde9d7 @josevalim Solve some pendencies.
josevalim authored
7 require 'rails/engine'
dc677f7 tests pass with requiring the frameworks in rails.rb
Carlhuda authored
8
accd9b4 @josh Restore "Start Rails::Application object
josh authored
9 module Rails
271a552 @claudiob [ci skip] Remove comments about Rails 3.1
claudiob authored
10 # An Engine with the responsibility of coordinating the whole boot process.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
11 #
12 # == Initialization
13 #
dad7fdc @spastorino Rails::Plugin has gone
spastorino authored
14 # Rails::Application is responsible for executing all railties and engines
eb716f6 @mjankowski grammar/tense correction to rails application doc
mjankowski authored
15 # initializers. It also executes some bootstrap initializers (check
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
16 # Rails::Application::Bootstrap) and finishing initializers, after all the others
17 # are executed (check Rails::Application::Finisher).
18 #
19 # == Configuration
20 #
21 # Besides providing the same configuration as Rails::Engine and Rails::Railtie,
22 # the application object has several specific configurations, for example
11bc348 @josevalim Remove allow_concurrency as a flag
josevalim authored
23 # "cache_classes", "consider_all_requests_local", "filter_parameters",
dad7fdc @spastorino Rails::Plugin has gone
spastorino authored
24 # "logger" and so forth.
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
25 #
26 # Check Rails::Application::Configuration to see them all.
27 #
28 # == Routes
29 #
30 # The application object is also responsible for holding the routes and reloading routes
31 # whenever the files change in development.
32 #
45e6028 @wycats Removing Metal from Rails 3.
wycats authored
33 # == Middlewares
781d0a9 @josevalim Add docs for Railtie, Engine, Plugin and Application.
josevalim authored
34 #
45e6028 @wycats Removing Metal from Rails 3.
wycats authored
35 # The Application is also responsible for building the middleware stack.
9cfeefb @wycats Reorganized initializers a bit to enable better hooks for common case…
wycats authored
36 #
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
37 # == Booting process
38 #
39 # The application is also responsible for setting up and executing the booting
40 # process. From the moment you require "config/application.rb" in your app,
41 # the booting process goes like this:
42 #
43 # 1) require "config/boot.rb" to setup load paths
44 # 2) require railties and engines
45 # 3) Define Rails.application as "class MyApp::Application < Rails::Application"
46 # 4) Run config.before_configuration callbacks
47 # 5) Load config/environments/ENV.rb
48 # 6) Run config.before_initialize callbacks
49 # 7) Run Railtie#initializer defined by railties, engines and application.
11aa167 @josevalim Revert "Provide a unique point for running initializers."
josevalim authored
50 # One by one, each engine sets up its load paths, routes and runs its config/initializers/* files.
ff25b0e @wangjohn Renumbering the comments in the application boot process.
wangjohn authored
51 # 8) Custom Railtie#initializers added by railties, engines and applications are executed
52 # 9) Build the middleware stack and run to_prepare callbacks
53 # 10) Run config.before_eager_load and eager_load! if eager_load is true
54 # 11) Run config.after_initialize callbacks
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
55 #
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
56 # == Multiple Applications
57 #
58 # If you decide to define multiple applications, then the first application
59 # that is initialized will be set to +Rails.application+, unless you override
60 # it with a different application.
61 #
62 # To create a new application, you can instantiate a new instance of a class
63 # that has already been created:
64 #
65 # class Application < Rails::Application
66 # end
67 #
68 # first_application = Application.new
69 # second_application = Application.new(config: first_application.config)
70 #
71 # In the above example, the configuration from the first application was used
72 # to initialize the second application. You can also use the +initialize_copy+
73 # on one of the applications to create a copy of the application which shares
74 # the configuration.
75 #
76 # If you decide to define rake tasks, runners, or initializers in an
77 # application other than +Rails.application+, then you must run those
78 # these manually.
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
79 class Application < Engine
685309c @wangjohn Creating a class to build the default middleware stack.
wangjohn authored
80 autoload :Bootstrap, 'rails/application/bootstrap'
81 autoload :Configuration, 'rails/application/configuration'
82 autoload :DefaultMiddlewareStack, 'rails/application/default_middleware_stack'
83 autoload :Finisher, 'rails/application/finisher'
84 autoload :Railties, 'rails/engine/railties'
85 autoload :RoutesReloader, 'rails/application/routes_reloader'
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
86
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
87 class << self
7fcf859 @josevalim Massive cleanup in Railties and load stack.
josevalim authored
88 def inherited(base)
89 super
d25fe31 @tenderlove lazily instantiate application subclasses
tenderlove authored
90 Rails.app_class = base
9dbcac7 @tenderlove add lib to $LOAD_PATH on application inhertence. fixes #17106
tenderlove authored
91 add_lib_to_load_path!(find_root(base.called_from))
e4d7e50 Moving more initializers into the application object
Carl Lerche authored
92 end
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
93
2296989 @tenderlove defer running after_config hooks until after the object is allocated
tenderlove authored
94 def instance
95 super.run_load_hooks!
96 end
97
8121eef @tenderlove add a new constructor that runs load hooks
tenderlove authored
98 def create(initial_variable_values = {}, &block)
99 new(initial_variable_values, &block).run_load_hooks!
100 end
101
9dbcac7 @tenderlove add lib to $LOAD_PATH on application inhertence. fixes #17106
tenderlove authored
102 def find_root(from)
103 find_root_with_flag "config.ru", from, Dir.pwd
104 end
105
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
106 # Makes the +new+ method public.
107 #
108 # Note that Rails::Application inherits from Rails::Engine, which
109 # inherits from Rails::Railtie and the +new+ method on Rails::Railtie is
110 # private
111 public :new
897164d Conceptually unify instance & global initializers
Yehuda Katz + Carl Lerche authored
112 end
6f6a589 Create the application object from config/environment.rb
Yehuda Katz + Carl Lerche authored
113
f9da785 @jeremy Move background jobs to the 'jobs' branch until fully baked. Not ship…
jeremy authored
114 attr_accessor :assets, :sandbox
52e01fc @josevalim Everyone receives app as argument for consistency.
josevalim authored
115 alias_method :sandbox?, :sandbox
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files …
josevalim authored
116 attr_reader :reloaders
52e01fc @josevalim Everyone receives app as argument for consistency.
josevalim authored
117
5ad7f8a @robin850 Use Ruby 1.9 Hash syntax in railties
robin850 authored
118 delegate :default_url_options, :default_url_options=, to: :routes
eedbf87 @drogus New way of generating urls for Application from Engine.
drogus authored
119
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
120 INITIAL_VARIABLES = [:config, :railties, :routes_reloader, :reloaders,
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
121 :routes, :helpers, :app_env_config, :secrets] # :nodoc:
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
122
123 def initialize(initial_variable_values = {}, &block)
124 super()
2be4916 @rafaelfranca Make possibile to get different message verifiers
rafaelfranca authored
125 @initialized = false
126 @reloaders = []
127 @routes_reloader = nil
128 @app_env_config = nil
129 @ordered_railties = nil
130 @railties = nil
131 @message_verifiers = {}
2296989 @tenderlove defer running after_config hooks until after the object is allocated
tenderlove authored
132 @ran_load_hooks = false
133
134 # are these actually used?
135 @initial_variable_values = initial_variable_values
136 @block = block
137 end
138
139 # Returns true if the application is initialized.
140 def initialized?
141 @initialized
142 end
143
144 def run_load_hooks! # :nodoc:
145 return self if @ran_load_hooks
146 @ran_load_hooks = true
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
147 ActiveSupport.run_load_hooks(:before_configuration, self)
148
2296989 @tenderlove defer running after_config hooks until after the object is allocated
tenderlove authored
149 @initial_variable_values.each do |variable_name, value|
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
150 if INITIAL_VARIABLES.include?(variable_name)
151 instance_variable_set("@#{variable_name}", value)
152 end
153 end
154
2296989 @tenderlove defer running after_config hooks until after the object is allocated
tenderlove authored
155 instance_eval(&@block) if @block
156 self
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
157 end
158
75b9c2c @czarneckid Clarify the documentation on the Rails::Application#call method
czarneckid authored
159 # Implements call according to the Rack API. It simply
160 # dispatches the request to the underlying middleware stack.
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
161 def call(env)
0755d30 @eileencodes Use fullpath from Rack request rather than building it
eileencodes authored
162 req = ActionDispatch::Request.new env
163 env["ORIGINAL_FULLPATH"] = req.fullpath
164 env["ORIGINAL_SCRIPT_NAME"] = req.script_name
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
165 super(env)
166 end
167
168 # Reload application routes regardless if they changed or not.
169 def reload_routes!
170 routes_reloader.reload!
171 end
172
0479bff @NZKoz Provide access to the application's KeyGenerator
NZKoz authored
173 # Return the application's KeyGenerator
174 def key_generator
175 # number of iterations selected based on consultation with the google security
176 # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
70c83f4 @carlosantoniodasilva Remove useless begin..end
carlosantoniodasilva authored
177 @caching_key_generator ||=
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
178 if secrets.secret_key_base
179 key_generator = ActiveSupport::KeyGenerator.new(secrets.secret_key_base, iterations: 1000)
851e8fe @spastorino Cache generated keys per KeyGenerator instance using salt + key_size
spastorino authored
180 ActiveSupport::CachingKeyGenerator.new(key_generator)
181 else
db5f1a4 @bf4 `secret_token` is now saved in `Rails.application.secrets.secret_token`
bf4 authored
182 ActiveSupport::LegacyKeyGenerator.new(secrets.secret_token)
851e8fe @spastorino Cache generated keys per KeyGenerator instance using salt + key_size
spastorino authored
183 end
0479bff @NZKoz Provide access to the application's KeyGenerator
NZKoz authored
184 end
185
d3d8498 @rafaelfranca Fix typos
rafaelfranca authored
186 # Returns a message verifier object.
69ac53c @rafaelfranca Add documentation and CHANGELOG entry to Application#verifier
rafaelfranca authored
187 #
d3d8498 @rafaelfranca Fix typos
rafaelfranca authored
188 # This verifier can be used to generate and verify signed messages in the application.
69ac53c @rafaelfranca Add documentation and CHANGELOG entry to Application#verifier
rafaelfranca authored
189 #
f98bd42 @rafaelfranca No need to configure salts
rafaelfranca authored
190 # It is recommended not to use the same verifier for different things, so you can get different
191 # verifiers passing the +verifier_name+ argument.
2be4916 @rafaelfranca Make possibile to get different message verifiers
rafaelfranca authored
192 #
193 # ==== Parameters
194 #
61f6b47 @rafaelfranca Change the message verifier argument to verifier_name
rafaelfranca authored
195 # * +verifier_name+ - the name of the message verifier.
2be4916 @rafaelfranca Make possibile to get different message verifiers
rafaelfranca authored
196 #
197 # ==== Examples
198 #
61f6b47 @rafaelfranca Change the message verifier argument to verifier_name
rafaelfranca authored
199 # message = Rails.application.message_verifier('sensitive_data').generate('my sensible data')
200 # Rails.application.message_verifier('sensitive_data').verify(message)
69ac53c @rafaelfranca Add documentation and CHANGELOG entry to Application#verifier
rafaelfranca authored
201 # # => 'my sensible data'
202 #
f98bd42 @rafaelfranca No need to configure salts
rafaelfranca authored
203 # See the +ActiveSupport::MessageVerifier+ documentation for more information.
61f6b47 @rafaelfranca Change the message verifier argument to verifier_name
rafaelfranca authored
204 def message_verifier(verifier_name)
205 @message_verifiers[verifier_name] ||= begin
bfdae17 @rafaelfranca Make possible to use symbol as the verifier name
rafaelfranca authored
206 secret = key_generator.generate_key(verifier_name.to_s)
2330017 @rafaelfranca Add application verifier
rafaelfranca authored
207 ActiveSupport::MessageVerifier.new(secret)
208 end
209 end
210
9629dea @rafaelfranca Add Rails::Application#config_for
rafaelfranca authored
211 # Convenience for loading config/foo.yml for the current Rails env.
212 #
213 # Example:
214 #
215 # # config/exception_notification.yml:
216 # production:
217 # url: http://127.0.0.1:8080
218 # namespace: my_app_production
219 # development:
220 # url: http://localhost:3001
221 # namespace: my_app_development
222 #
223 # # config/production.rb
994d3eb Standardize on `Rails.application` [ci skip]
Tamir Duberstein authored
224 # Rails.application.configure do
9629dea @rafaelfranca Add Rails::Application#config_for
rafaelfranca authored
225 # config.middleware.use ExceptionNotifier, config_for(:exception_notification)
226 # end
227 def config_for(name)
228 yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
229
230 if yaml.exist?
231 require "erb"
232 (YAML.load(ERB.new(yaml.read).result) || {})[Rails.env] || {}
233 else
234 raise "Could not load configuration. No such file - #{yaml}"
235 end
236 rescue Psych::SyntaxError => e
237 raise "YAML syntax error occurred while parsing #{yaml}. " \
238 "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
239 "Error: #{e.message}"
240 end
241
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
242 # Stores some of the Rails initial environment parameters which
243 # will be used by middlewares and engines to configure themselves.
244 def env_config
862389c @josevalim Use @app_env_config instead of @env_config
josevalim authored
245 @app_env_config ||= begin
484ff7d @wangjohn Removing a repetitive comment and removing a deprecation warning.
wangjohn authored
246 validate_secret_key_config!
e272000 @spastorino Warn config.derive_keys will be true by default in 4.1
spastorino authored
247
248 super.merge({
249 "action_dispatch.parameter_filter" => config.filter_parameters,
86e3aaa @freegenie Adding filter capability to ActionController logs
freegenie authored
250 "action_dispatch.redirect_filter" => config.filter_redirect,
db5f1a4 @bf4 `secret_token` is now saved in `Rails.application.secrets.secret_token`
bf4 authored
251 "action_dispatch.secret_token" => secrets.secret_token,
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
252 "action_dispatch.secret_key_base" => secrets.secret_key_base,
e272000 @spastorino Warn config.derive_keys will be true by default in 4.1
spastorino authored
253 "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
254 "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
255 "action_dispatch.logger" => Rails.logger,
256 "action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner,
47da574 @spastorino Allow users to change the default salt if they want, shouldn't be nec…
spastorino authored
257 "action_dispatch.key_generator" => key_generator,
258 "action_dispatch.http_auth_salt" => config.action_dispatch.http_auth_salt,
259 "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt,
260 "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt,
b23ffd0 @lukesarnacki Allow session serializer key in config.session_store
lukesarnacki authored
261 "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt,
29be3f5 @strzalek Add config option for cookies digest
strzalek authored
262 "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
263 "action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest
e272000 @spastorino Warn config.derive_keys will be true by default in 4.1
spastorino authored
264 })
265 end
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
266 end
267
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
268 # If you try to define a set of rake tasks on the instance, these will get
269 # passed up to the rake tasks defined on the application's class.
270 def rake_tasks(&block)
271 self.class.rake_tasks(&block)
272 end
273
274 # Sends the initializers to the +initializer+ method defined in the
275 # Rails::Initializable module. Each Rails::Application class has its own
276 # set of initializers, as defined by the Initializable module.
277 def initializer(name, opts={}, &block)
278 self.class.initializer(name, opts, &block)
279 end
280
281 # Sends any runner called in the instance of a new application up
282 # to the +runner+ method defined in Rails::Railtie.
283 def runner(&blk)
284 self.class.runner(&blk)
285 end
286
43f5250 @rafaelfranca Make console and generators blocks works at Application instance level
rafaelfranca authored
287 # Sends any console called in the instance of a new application up
288 # to the +console+ method defined in Rails::Railtie.
289 def console(&blk)
290 self.class.console(&blk)
291 end
292
293 # Sends any generators called in the instance of a new application up
294 # to the +generators+ method defined in Rails::Railtie.
295 def generators(&blk)
296 self.class.generators(&blk)
297 end
298
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
299 # Sends the +isolate_namespace+ method up to the class method.
300 def isolate_namespace(mod)
301 self.class.isolate_namespace(mod)
302 end
303
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
304 ## Rails internal API
305
9e081ca @josevalim Improve documentation for add_lib_to_load_paths!
josevalim authored
306 # This method is called just after an application inherits from Rails::Application,
307 # allowing the developer to load classes in lib and use them during application
308 # configuration.
309 #
310 # class MyApplication < Rails::Application
311 # require "my_backend" # in lib/my_backend
312 # config.i18n.backend = MyBackend
313 # end
314 #
315 # Notice this method takes into consideration the default root path. So if you
316 # are changing config.root inside your application definition or having a custom
317 # Rails application, you will need to add lib to $LOAD_PATH on your own in case
318 # you need to load files in lib/ during the application configuration as well.
9dbcac7 @tenderlove add lib to $LOAD_PATH on application inhertence. fixes #17106
tenderlove authored
319 def self.add_lib_to_load_path!(root) #:nodoc:
320 path = File.join root, 'lib'
4d4ff53 @tenderlove clean up some warnings on trunk ruby
tenderlove authored
321 if File.exist?(path) && !$LOAD_PATH.include?(path)
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
322 $LOAD_PATH.unshift(path)
323 end
5a0d73f @josevalim Add lib to load paths when application is inherited to be able to loa…
josevalim authored
324 end
325
9e081ca @josevalim Improve documentation for add_lib_to_load_paths!
josevalim authored
326 def require_environment! #:nodoc:
d649bf1 @josevalim Provide a cleaner syntax for paths configuration that does not rely o…
josevalim authored
327 environment = paths["config/environment"].existent.first
13d66cd @josevalim Extract Railtie load from application.
josevalim authored
328 require environment if environment
d982fe2 Replace reopening the class with App.configure as an alias to class_eval
Carlhuda authored
329 end
330
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
331 def routes_reloader #:nodoc:
3049e64 @drogus Moved Rails::RoutesReloader to Rails::Application::RoutesReloader
drogus authored
332 @routes_reloader ||= RoutesReloader.new
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
333 end
5f8e48c @josh Move route reloading into railties
josh authored
334
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
335 # Returns an array of file paths appended with a hash of
336 # directories-extensions suitable for ActiveSupport::FileUpdateChecker
337 # API.
338 def watchable_args #:nodoc:
516f102 @ndbroadbent Refactored watchable_args and build_original_fullpath methods in rail…
ndbroadbent authored
339 files, dirs = config.watchable_files.dup, config.watchable_dirs.dup
fa1d9a8 @josevalim Speed up development by only reloading classes if dependencies files …
josevalim authored
340
341 ActiveSupport::Dependencies.autoload_paths.each do |path|
342 dirs[path.to_s] = [:rb]
343 end
344
80256ab @josevalim FileUpdateChecker should be able to handle deleted files.
josevalim authored
345 [files, dirs]
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
346 end
347
348 # Initialize the application passing the given group. By default, the
2d5a6de @hone `initialize_on_precompile` is not used anymore.
hone authored
349 # group is :default
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
350 def initialize!(group=:default) #:nodoc:
abeb0ff @drogus Ensure that Rails.application.initialize! is called only once
drogus authored
351 raise "Application has been already initialized." if @initialized
eb367af @josevalim `rake assets:precompile` loads the application but does not initializ…
josevalim authored
352 run_initializers(group, self)
abeb0ff @drogus Ensure that Rails.application.initialize! is called only once
drogus authored
353 @initialized = true
80130d1 @josevalim Extract routes reloading responsibilities from application and load t…
josevalim authored
354 self
5f8e48c @josh Move route reloading into railties
josh authored
355 end
356
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
357 def initializers #:nodoc:
e9793c6 @spastorino Makes this code a bit more clear
spastorino authored
358 Bootstrap.initializers_for(self) +
50b6110 @josevalim Remove unused responsibilities and add a few load definitions to engines
josevalim authored
359 railties_initializers(super) +
e9793c6 @spastorino Makes this code a bit more clear
spastorino authored
360 Finisher.initializers_for(self)
98240c4 @josevalim Get rid of initializers global and create i18n railtie.
josevalim authored
361 end
788fce2 @josevalim Create configurable modules and ensure that they are added only on di…
josevalim authored
362
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
363 def config #:nodoc:
9dbcac7 @tenderlove add lib to $LOAD_PATH on application inhertence. fixes #17106
tenderlove authored
364 @config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
32a5b49 @drogus Move singleton pattern to Railtie and remove Engine::Configurable and…
drogus authored
365 end
366
08dc924 @wangjohn Allowing multiple rails applications in the same ruby instance.
wangjohn authored
367 def config=(configuration) #:nodoc:
368 @config = configuration
369 end
370
2f7b72b @tgxworld Rails::Application#secrets should be documented.
tgxworld authored
371 # Returns secrets added to config/secrets.yml.
372 #
373 # Example:
374 #
375 # development:
376 # secret_key_base: 836fa3665997a860728bcb9e9a1e704d427cfc920e79d847d79c8a9a907b9e965defa4154b2b86bdec6930adbe33f21364523a6f6ce363865724549fdfc08553
377 # test:
378 # secret_key_base: 5a37811464e7d378488b0f073e2193b093682e4e21f5d6f3ae0a4e1781e61a351fdc878a843424e81c73fb484a40d23f92c8dafac4870e74ede6e5e174423010
379 # production:
380 # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
381 # namespace: my_app_production
382 #
383 # +Rails.application.secrets.namespace+ returns +my_app_production+ in the
384 # production environment.
385 def secrets
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
386 @secrets ||= begin
387 secrets = ActiveSupport::OrderedOptions.new
bb7537b @guilleiguaran Rename tokens.yml to secrets.yml
guilleiguaran authored
388 yaml = config.paths["config/secrets"].first
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
389 if File.exist?(yaml)
390 require "erb"
37e30d2 @senny do not crash when `config/secrets.yml` is blank.
senny authored
391 all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {}
392 env_secrets = all_secrets[Rails.env]
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
393 secrets.merge!(env_secrets.symbolize_keys) if env_secrets
394 end
395
396 # Fallback to config.secret_key_base if secrets.secret_key_base isn't set
397 secrets.secret_key_base ||= config.secret_key_base
1d1239d @rafaelfranca No need to sync config.secret_token and secrets.secret_token
rafaelfranca authored
398 # Fallback to config.secret_token if secrets.secret_token isn't set
399 secrets.secret_token ||= config.secret_token
3eaa298 @guilleiguaran Load secret_key_base from tokens.yml, fallback to config.secret_key_base
guilleiguaran authored
400
401 secrets
402 end
403 end
404
405 def secrets=(secrets) #:nodoc:
406 @secrets = secrets
407 end
408
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
409 def to_app #:nodoc:
8496be7 @guilleiguaran Fixing Rails::Server#app under Rack::URLMap
guilleiguaran authored
410 self
411 end
412
27f0add @josevalim Improve docs for Rails::Application and add routes_reloader_hook and …
josevalim authored
413 def helpers_paths #:nodoc:
fd86a1b @josevalim Rely on a public contract between railties instead of accessing railt…
josevalim authored
414 config.helpers_paths
415 end
416
b058897 @matthewd Ensure we supply Kernel#y for 1.9 too
matthewd authored
417 console do
418 require "pp"
419 end
420
421 console do
422 unless ::Kernel.private_method_defined?(:y)
185d7cd @claudiob Remove Psych hack for Ruby 1.9
claudiob authored
423 require "psych/y"
b058897 @matthewd Ensure we supply Kernel#y for 1.9 too
matthewd authored
424 end
425 end
426
435e8d7 @huoxito Dont mess with default order engines load
huoxito authored
427 # Return an array of railties respecting the order they're loaded
428 # and the order specified by the +railties_order+ config.
429 #
d969405 @robin850 Some documentation edits [ci skip]
robin850 authored
430 # While running initializers we need engines in reverse order here when
431 # copying migrations from railties ; we need them in the order given by
432 # +railties_order+.
50de394 @arunagw rake railties:install:migrations respects the order of railties
arunagw authored
433 def migration_railties # :nodoc:
435e8d7 @huoxito Dont mess with default order engines load
huoxito authored
434 ordered_railties.flatten - [self]
50de394 @arunagw rake railties:install:migrations respects the order of railties
arunagw authored
435 end
436
2fe70c1 @josevalim Booya, sprockets now works from Engines.
josevalim authored
437 protected
438
439 alias :build_middleware_stack :app
612454e @josh Move sprockets initializers back to application
josh authored
440
50b6110 @josevalim Remove unused responsibilities and add a few load definitions to engines
josevalim authored
441 def run_tasks_blocks(app) #:nodoc:
442 railties.each { |r| r.run_tasks_blocks(app) }
443 super
444 require "rails/tasks"
445 task :environment do
9cac69c @pftg #11381: Ignore config.eager_load=true for rake
pftg authored
446 ActiveSupport.on_load(:before_initialize) { config.eager_load = false }
447
50b6110 @josevalim Remove unused responsibilities and add a few load definitions to engines
josevalim authored
448 require_environment!
449 end
450 end
451
452 def run_generators_blocks(app) #:nodoc:
453 railties.each { |r| r.run_generators_blocks(app) }
454 super
455 end
456
457 def run_runner_blocks(app) #:nodoc:
458 railties.each { |r| r.run_runner_blocks(app) }
459 super
460 end
461
462 def run_console_blocks(app) #:nodoc:
463 railties.each { |r| r.run_console_blocks(app) }
464 super
465 end
466
467 # Returns the ordered railties for this application considering railties_order.
468 def ordered_railties #:nodoc:
469 @ordered_railties ||= begin
470 order = config.railties_order.map do |railtie|
471 if railtie == :main_app
472 self
473 elsif railtie.respond_to?(:instance)
474 railtie.instance
475 else
476 railtie
477 end
478 end
479
480 all = (railties - order)
481 all.push(self) unless (all + order).include?(self)
482 order.push(:all) unless order.include?(:all)
483
484 index = order.index(:all)
485 order[index] = all
435e8d7 @huoxito Dont mess with default order engines load
huoxito authored
486 order
50b6110 @josevalim Remove unused responsibilities and add a few load definitions to engines
josevalim authored
487 end
488 end
489
490 def railties_initializers(current) #:nodoc:
491 initializers = []
435e8d7 @huoxito Dont mess with default order engines load
huoxito authored
492 ordered_railties.reverse.flatten.each do |r|
50b6110 @josevalim Remove unused responsibilities and add a few load definitions to engines
josevalim authored
493 if r == self
494 initializers += current
495 else
496 initializers += r.initializers
497 end
498 end
499 initializers
500 end
501
0470ddc @josevalim Remove unnecessary Railties structure now that plugins are gone
josevalim authored
502 def default_middleware_stack #:nodoc:
685309c @wangjohn Creating a class to build the default middleware stack.
wangjohn authored
503 default_stack = DefaultMiddlewareStack.new(self, config, paths)
504 default_stack.build_stack
9ee6f3c @josevalim Bring config.allow_concurrency back
josevalim authored
505 end
506
484ff7d @wangjohn Removing a repetitive comment and removing a deprecation warning.
wangjohn authored
507 def validate_secret_key_config! #:nodoc:
db5f1a4 @bf4 `secret_token` is now saved in `Rails.application.secrets.secret_token`
bf4 authored
508 if secrets.secret_key_base.blank?
509 ActiveSupport::Deprecation.warn "You didn't set `secret_key_base`. " +
510 "Read the upgrade documentation to learn more about this new config option."
511
512 if secrets.secret_token.blank?
b93ae0c Error message no longer tells you to set the (deprecated) secret_token.
Dan authored
513 raise "Missing `secret_key_base` for '#{Rails.env}' environment, set this value in `config/secrets.yml`"
db5f1a4 @bf4 `secret_token` is now saved in `Rails.application.secrets.secret_token`
bf4 authored
514 end
484ff7d @wangjohn Removing a repetitive comment and removing a deprecation warning.
wangjohn authored
515 end
516 end
accd9b4 @josh Restore "Start Rails::Application object
josh authored
517 end
17a91a6 @dlee Logs should show overridden method; Issue 426
dlee authored
518 end
Something went wrong with that request. Please try again.