Class

Initializer

Extends:

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_plugins The set of loaded plugins.
Public Methods
add_plugin_load_paths 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_support_load_paths Add the load paths used by support functions such as the info controller
after_initialize Fires the user-supplied after_initialize block (Configuration#after_initialize)
check_ruby_version 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_cache
initialize_database 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_dependency_mechanism Sets the dependency loading mechanism based on the value of Configuration#cache_classes.
initialize_encoding 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_framework_caches
initialize_framework_logging 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_framework_settings 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_framework_views 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_logger 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_routing 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_temporary_session_directory
initialize_time_zone
initialize_whiny_nils Loads support for "whiny nil" (noisy warnings when methods are invoked on nil values) if Configuration#whiny_nils is true.
load_application_initializers
load_environment Loads the environment specified by Configuration#environment_path, which is typically one of development, test, or production.
load_observers
load_plugins 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_loader
process Sequentially step through all of the available initialization routines, in order (view execution order in source).
require_frameworks 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_autoload_paths Set the paths from which Rails will automatically load source files, and the load_once paths.
set_load_path Set the $LOAD_PATH based on the value of Configuration#load_paths. Duplicates are removed.
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.