Rails is no longer a singleton, and multiple applications can be initialized in a single Ruby process. The caveat is that these applications will share a single global configuration which is stored in Rails.config
, which is created as soon as the first rails application is initialized.
This also means that Rails.config
is available before the environment initialization occurs.
You can now initialize multiple rails applications. To do this, I've changed the initialization of an application to the following structure (you can see this inside of /config/application.rb
).
class Application < Rails::Application
end
Application.new do
config.time_zone = 'Eastern'
config.blah = 'blah'
end
This means that you can call Application.new
as many times as you would like. You don't have to actually create a subclass, and you can just call Rails::Application.new
, but creating a subclass is backwards compatible with the way applications have been initialized in the past.
When you configure an application now, you will be changing a global configuration object stored in Rails.config
. You can also configure this directly by doing something like this:
Rails.configure do |config|
config.time_zone = 'Eastern'
end
##Global Configuration
This PR still uses a global configuration for all rails app. Whenever a new application is created, it's configuration will be the same as the configuration of all the other rails applications. (This global config will be relaxed as I continue to work on this PR. The end goal is to make it so that each application has its own, separate configuration).
In addition, the Rails
module stores the global rake tasks. These rake tasks are shared across all applications.
##Backwards Compatibility
I've made sure that this PR preserves a lot of old functionality. Initializing and configuring an application in the old way is still possible. For example: inside /config/application.rb
you can still define an application as follows:
class Application < Rails::Application
config.time_zone = 'Eastern'
end
Application.initialize!
The call to Application.initialize!
sets Rails.application
to a new instance of Application
, but cannot be called twice.