initializer.rb
Rails::Initialzier是用来建立Rails环境的主要类。Initializer是在config/environment.rb里面触发的,它里面包含了下面的一个代码块:
Rails::Initializer.run do |config|
# (configuration)
end
Rails::Initializer.run带进一个新的对象Rails::Configuration到这个代码块里。然后,run创建一个新的Rails::Initializer对象并且调用他的process方法,这个方法依次用下面的步骤来初始化Rails:
1. check_ruby_version: 保证使用的Ruby版本大于1.8.2
2. set_load_path: 添加框架的路径(RailTies, ActionPack, ActiveSupport, ActiveRecord, Action Mailer, and Action Web Service)和应用装载的路径到Ruby的装载路径里。框架是在vendor/rails或者在RAILS_FRAMEWORK_ROOT指定的路径装载的。
3. require_frameworks: Loads each framework listed in the frameworks configuration option. If the framework path was not specified in RAILS_FRAMEWORK_ROOT and it does not exist in vendor/rails, Initializer will assume the frameworks are installed as RubyGems.
4.
set_autoload_paths: Sets the autoload paths based on the values of the load_ paths and load_once_paths configuration variables. These determine which paths will be searched to resolve unknown constants. The load_paths option 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 to u for UTF-8 support throughout Rails.
7.
initialize_database: If ActiveRecord is being used, sets up its database configuration and connects to the database server.
8.
initialize_logger: Sets up the logger and sets the top-level constant RAILS_ DEFAULT_LOGGER to the instance. If logger is specified in the configuration, it is used. If not, a new logger is created and directed to the log_path specified. If that fails, a warning is displayed and logging is redirected to standard error.
9.
initialize_framework_logging: Sets the logger for ActiveRecord, ActionController, 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 the view_path configuration item.
11.
initialize_dependency_mechanism: Sets Dependencies.mechanism (which determines whether to use require or load to load files) based on the setting of the cache_classes configuration item.
12.
initialize_whiny_nils: If the whiny_nils configuration item is true, adds the WhinyNil extensions (that complain when trying to call id or other methods on nil) to NilClass.
13.
initialize_temporary_directories: Sets ActionController's temporary session and cache directories if they exist in the filesystem.
14.
initialize_framework_settings: Transforms the framework-specific configuration settings into method calls on the frameworks' Base classes. For example, consider the configuration option:
config.active_record.schema_format = :sql
The config.active_record object is an instance of Rails::OrderedOptions, which is basically an ordered hash (ordered to keep the configuration directives in order). During initialization, the initialize_framework_settings method transforms it into the following:
ActiveRecord::Base.schema_format = :sql
This offers the advantage that the Configuration object doesn't have to be updated every time a framework adds or changes a configuration option.
15.
add_support_load_paths: Adds load paths for support functions. This function is currently empty.
16.
load_plugins: Loads the plugins from paths in the plugin_paths configuration item (default vendor/plugins). If a plugins configuration item is specified, load those plugins respecting that load order. Plugins are loaded close to the end of the process so that they can override any already loaded component.
17.
load_observers: Instantiates ActiveRecord observers. This is done after plugins so that plugins have an opportunity to modify the observer classes.
18.
initialize_routing: Loads and processes the routes. Also sets the controller paths from the controller_paths configuration item.
19.
after_initialize: Calls any user-defined after_initialize callback. These call-backs are defined in the configuration block by config.after_initialize { … }.
20.
load_application_initializers: Loads all Rubyfiles in RAILS_ROOT/config/ initializers and any of its subdirectories. Old framework initialization that may previouslyhave been contained in config/environment.rb can now properly be broken out into separate initializers.
Now the framework is ready to receive requests.
分享到:
相关推荐
rails-dev-box, 面向 Ruby on Rails 核心开发的虚拟机 用于 Ruby on Rails 核心开发的虚拟机简介注意:这个虚拟机不是为 Rails 应用程序开发而设计的,只是为。 这个项目自动设置开发环境,以便在 Ruby on Rails ...
rails-2.3.5.gem redmine必须gem
"rails-2.1.0-gem"是Rails框架的一个特定版本,即2.1.0的gem包,用于在Ruby环境中安装和管理Rails框架。 Rails的核心理念是“约定优于配置”(Convention over Configuration),这意味着开发者可以遵循一套预设的...
预习: 实时示例: : 如何添加到Gemfile gem 'rails-settings-ui'然后加gem 'rails-settings-cached'要么gem 'rails-settings'或您的扶手设置。 如果要使用引导程序界面,则还需要在应用程序中包含引导程序样式表...
rails-beginner-s-guide是Rails 指导手册,帮组学习了解rails开发
rails-documentation-2-0-2
`rails-chm-2-0-2.rar` 是一个针对Rails 2.0.2版本的CHM(Compiled HTML Help)文件,这种格式通常用来存储组织化的HTML文档,便于用户离线浏览。这个压缩包包含了一份完整的Rails 2.0.2帮助文档,是学习和使用Rails...
rails-ftw-v0.18-2.1.5-4.1.8.exe用于在windows环境下搭建readmine环境
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
是我搭建redmine过程中所使用到的资源,因为感到很多东西不太好找,所以给上传上来,供自己和大家使用。
本文将深入探讨"rails-react-components-源码.rar"中的关键知识点,帮助开发者理解如何在Rails应用中集成React组件。 1. **React组件化开发** React的核心概念是组件,它允许我们将UI拆分为独立、可重用的部分。在...
版本为:rails-2.3.8.gem 可使用指令安装:gem install rails-2.3.8.gem
标题 "rails-documentation-1-2-1.zip" 暗示这是一份关于 Ruby on Rails 框架的文档,版本为 1.2.1。Ruby 是一种面向对象的编程语言,而 Rails 是一个基于 Ruby 的开源 Web 应用程序框架,遵循 Model-View-...
Ember CLI是Ember.js的命令行接口,提供了一整套构建工具,用于快速初始化、开发和维护Ember应用。它包括了自动化任务(如编译、测试和热重载),以及管理依赖关系的功能。 2. **Rails集成** Ember CLI Rails将...
"Advanced Rails" 涵盖了Rails开发中的高级主题和技术,是Ruby on Rails学习进阶的重要资源,尤其适合已经对基础Rails有一定了解的开发者。 在Web开发领域,Rails以其高效、简洁的代码和“约定优于配置”的哲学吸引...
rails-settings, 使用 Ruby on Rails 管理设置 Rails的设置 ruby gem,通过在单独的数据库表中将它们存储为序列化的哈希来处理。 包含命名空间和默认值。要求ruby 1.9.3或者更高版本Rails 3.1或者更高版本( 包括 ...
用于Ruby on Rails核心开发的虚拟机 介绍 请注意,该虚拟机并非为...host $ cd rails-dev-box host $ vagrant up 而已。 安装完成后,您可以使用以下命令访问虚拟机: host $ vagrant ssh Welcome to Ubuntu 20.10
rails-documentation-1-2-0-rc1.chm