The Initializer is responsible for processing the Rails configuration, such as setting the $LOAD_PATH, requiring the right frameworks, initializing logging, and more. It can be run either as a single command that’ll just use the default configuration, like this:
Rails::Initializer.run
But normally it’s more interesting to pass in a custom configuration through the block running:
Rails::Initializer.run do |config| config.frameworks -= [ :action_mailer ] end
This will use the default configuration options from Rails::Configuration, but allow for overwriting on select areas.
| Public Attributes | |
|---|---|
| configuration | The Configuration instance used by this Initializer instance. |
| loaded_ |
The set of loaded plugins. |
| Public Methods | |
|---|---|
| add_ |
Adds all load paths from plugins to the global set of load paths, so that code from plugins can be required (explicitly or automatically via Dependencies). |
| add_ |
Add the load paths used by support functions such as the info controller |
| after_ |
Fires the user-supplied after_initialize block (Configuration#after_initialize) |
| check_ |
Check for valid Ruby version This is done in an external file, so we can use it from the `rails` program as well without duplication. |
| initialize_ |
|
| initialize_ |
This initialization routine does nothing unless :active_record is one of the frameworks to load (Configuration#frameworks). If it is, this sets the database configuration from Configuration#database_configuration and then establishes the connection. |
| initialize_ |
Sets the dependency loading mechanism based on the value of Configuration#cache_classes. |
| initialize_ |
For Ruby 1.8, this initialization sets $KCODE to ‘u’ to enable the multibyte safe operations. Plugin authors supporting other encodings should override this behaviour and set the relevant default_charset on ActionController::Base. |
| initialize_ |
|
| initialize_ |
Sets the logger for ActiveRecord, ActionController, and ActionMailer (but only for those frameworks that are to be loaded). If the framework’s logger is already set, it is not changed, otherwise it is set to use RAILS_DEFAULT_LOGGER. |
| initialize_ |
Initializes framework-specific settings for each of the loaded frameworks (Configuration#frameworks). The available settings map to the accessors on each of the corresponding Base classes. |
| initialize_ |
Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+ (but only for those frameworks that are to be loaded). If the framework’s paths have already been set, it is not changed, otherwise it is set to use Configuration#view_path. |
| initialize_ |
If the RAILS_DEFAULT_LOGGER constant is already set, this initialization routine does nothing. If the constant is not set, and Configuration#logger is not nil, this also does nothing. Otherwise, a new logger instance is created at Configuration#log_path, with a default log level of Configuration#log_level. |
| initialize_ |
If ActionController is not one of the loaded frameworks (Configuration#frameworks) this does nothing. Otherwise, it loads the routing definitions and sets up loading module used to lazily load controllers (Configuration#controller_paths). |
| initialize_ |
|
| initialize_ |
|
| initialize_ |
Loads support for "whiny nil" (noisy warnings when methods are invoked on nil values) if Configuration#whiny_nils is true. |
| load_ |
|
| load_ |
Loads the environment specified by Configuration#environment_path, which is typically one of development, test, or production. |
| load_ |
|
| load_ |
Loads all plugins in config.plugin_paths. plugin_paths defaults to vendor/plugins but may also be set to a list of paths, such as |
| new | Create a new Initializer instance that references the given Configuration instance. |
| plugin_ |
|
| process | Sequentially step through all of the available initialization routines, in order (view execution order in source). |
| require_ |
Requires all frameworks specified by the Configuration#frameworks list. By default, all frameworks (ActiveRecord, ActiveSupport, ActionPack, ActionMailer, and ActiveResource) are loaded. |
| run | Runs the initializer. By default, this will invoke the #process method, which simply executes all of the initialization routines. Alternately, you can specify explicitly which initialization routine you want: |
| set_ |
Set the paths from which Rails will automatically load source files, and the load_once paths. |
| set_ |
Set the $LOAD_PATH based on the value of Configuration#load_paths. Duplicates are removed. |
<code/>and<pre/>for code samples.