Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

76 | Chapter 2: ActiveSupport and RailTies


Rails::Initializer.runyields a newRails::Configurationobject to the block. Then
runcreates a newRails::Initializerobject and calls itsprocessmethod, which
takes the following steps in order to initialize Rails:


1.check_ruby_version: Ensures that Ruby 1.8.2 or above (but not 1.8.3) is being
used.
2.set_load_path: Adds the framework paths (RailTies, ActionPack,*ActiveSupport,
ActiveRecord, Action Mailer, and Action Web Service) and the application’s
load paths to the Ruby load path. The framework is loaded fromvendor/railsor
a location specified inRAILS_FRAMEWORK_ROOT.
3.require_frameworks: Loads each framework listed in theframeworksconfigura-
tion option. If the framework path was not specified inRAILS_FRAMEWORK_ROOT
and it does not exist invendor/rails, Initializer will assume the frameworks are
installed as RubyGems.
4.set_autoload_paths: Sets the autoload paths based on the values of theload_
pathsandload_once_pathsconfiguration variables. These determine which paths
will be searched to resolve unknown constants. Theload_pathsoption is the
same one that provided the application’s load paths in step 2.
5.load_environment: Loads and evaluates the environment-specific (development,
production, or test) configuration file.
6.initialize_encoding: Sets$KCODE tou for UTF-8 support throughout Rails.
7.initialize_database: If ActiveRecord is being used, sets up its database configu-
ration and connects to the database server.
8.initialize_logger: Sets up the logger and sets the top-level constantRAILS_
DEFAULT_LOGGERto the instance. Ifloggeris specified in the configuration, it is
used. If not, a new logger is created and directed to thelog_pathspecified. If that
fails, a warning is displayed and logging is redirected to standard error.
9.initialize_framework_logging: Sets the logger for ActiveRecord, ActionControl-
ler, and Action Mailer (if they are being used) to the logger that was just set up.
10.initialize_framework_views: Sets the view path for ActionController and Action
Mailer to the value of theview_path configuration item.
11.initialize_dependency_mechanism: Sets Dependencies.mechanism (which deter-
mines whether to userequireorloadto load files) based on the setting of the
cache_classes configuration item.
12.initialize_whiny_nils: If thewhiny_nilsconfiguration item istrue, adds the
Whiny Nil extensions (that complain when trying to callidor other methods on
nil) toNilClass.


  • ActionPack = ActionController + ActionView.

Free download pdf