Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8fe66f1a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8fe66f1a
编写于
1月 07, 2010
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Run railtie and plugin initializers before app specific ones
上级
19e7c524
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
155 addition
and
130 deletion
+155
-130
railties/lib/rails.rb
railties/lib/rails.rb
+2
-0
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+2
-130
railties/lib/rails/bootstrap.rb
railties/lib/rails/bootstrap.rb
+140
-0
railties/test/application/initializer_test.rb
railties/test/application/initializer_test.rb
+11
-0
未找到文件。
railties/lib/rails.rb
浏览文件 @
8fe66f1a
...
...
@@ -32,6 +32,8 @@
RAILS_ENV
=
(
ENV
[
"RAILS_ENV"
]
||
ENV
[
"RACK_ENV"
]
||
"development"
).
dup
unless
defined?
(
RAILS_ENV
)
module
Rails
autoload
:Bootstrap
,
'rails/bootstrap'
# Needs to be duplicated from Active Support since its needed before Active
# Support is available. Here both Options and Hash are namespaced to prevent
# conflicts with other implementations AND with the classes residing in Active Support.
...
...
railties/lib/rails/application.rb
浏览文件 @
8fe66f1a
...
...
@@ -83,8 +83,9 @@ def load_tasks
end
def
initializers
initializers
=
super
initializers
=
Bootstrap
.
new
(
self
).
initializers
plugins
.
each
{
|
p
|
initializers
+=
p
.
initializers
}
initializers
+=
super
initializers
end
...
...
@@ -103,135 +104,6 @@ def call(env)
@app
.
call
(
env
)
end
initializer
:load_all_active_support
do
require
"active_support/all"
unless
config
.
active_support
.
bare
end
# Set the <tt>$LOAD_PATH</tt> based on the value of
# Configuration#load_paths. Duplicates are removed.
initializer
:set_load_path
do
config
.
paths
.
add_to_load_path
$LOAD_PATH
.
uniq!
end
# Set the paths from which Rails will automatically load source files, and
# the load_once paths.
initializer
:set_autoload_paths
do
require
'active_support/dependencies'
ActiveSupport
::
Dependencies
.
load_paths
=
config
.
load_paths
.
uniq
ActiveSupport
::
Dependencies
.
load_once_paths
=
config
.
load_once_paths
.
uniq
extra
=
ActiveSupport
::
Dependencies
.
load_once_paths
-
ActiveSupport
::
Dependencies
.
load_paths
unless
extra
.
empty?
abort
<<-
end_error
load_once_paths must be a subset of the load_paths.
Extra items in load_once_paths:
#{
extra
*
','
}
end_error
end
# Freeze the arrays so future modifications will fail rather than do nothing mysteriously
config
.
load_once_paths
.
freeze
end
# Create tmp directories
initializer
:ensure_tmp_directories_exist
do
%w(cache pids sessions sockets)
.
each
do
|
dir_to_make
|
FileUtils
.
mkdir_p
(
File
.
join
(
root
,
'tmp'
,
dir_to_make
))
end
end
# Preload all frameworks specified by the Configuration#frameworks.
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
initializer
:preload_frameworks
do
ActiveSupport
::
Autoload
.
eager_autoload!
if
config
.
preload_frameworks
end
initializer
:initialize_cache
do
unless
defined?
(
RAILS_CACHE
)
silence_warnings
{
Object
.
const_set
"RAILS_CACHE"
,
ActiveSupport
::
Cache
.
lookup_store
(
config
.
cache_store
)
}
if
RAILS_CACHE
.
respond_to?
(
:middleware
)
# Insert middleware to setup and teardown local cache for each request
config
.
middleware
.
insert_after
(
:"Rack::Lock"
,
RAILS_CACHE
.
middleware
)
end
end
end
initializer
:initialize_logger
do
# if the environment has explicitly defined a logger, use it
next
if
Rails
.
logger
unless
logger
=
config
.
logger
begin
logger
=
ActiveSupport
::
BufferedLogger
.
new
(
config
.
log_path
)
logger
.
level
=
ActiveSupport
::
BufferedLogger
.
const_get
(
config
.
log_level
.
to_s
.
upcase
)
if
RAILS_ENV
==
"production"
logger
.
auto_flushing
=
false
end
rescue
StandardError
=>
e
logger
=
ActiveSupport
::
BufferedLogger
.
new
(
STDERR
)
logger
.
level
=
ActiveSupport
::
BufferedLogger
::
WARN
logger
.
warn
(
"Rails Error: Unable to access log file. Please ensure that
#{
config
.
log_path
}
exists and is chmod 0666. "
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
)
end
end
# TODO: Why are we silencing warning here?
silence_warnings
{
Object
.
const_set
"RAILS_DEFAULT_LOGGER"
,
logger
}
end
# Sets the logger for Active Record, Action Controller, and Action Mailer
# (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.
initializer
:initialize_framework_logging
do
ActiveSupport
::
Dependencies
.
logger
||=
Rails
.
logger
Rails
.
cache
.
logger
||=
Rails
.
logger
end
# Sets the dependency loading mechanism based on the value of
# Configuration#cache_classes.
initializer
:initialize_dependency_mechanism
do
# TODO: Remove files from the $" and always use require
ActiveSupport
::
Dependencies
.
mechanism
=
config
.
cache_classes
?
:require
:
:load
end
# Loads support for "whiny nil" (noisy warnings when methods are invoked
# on +nil+ values) if Configuration#whiny_nils is true.
initializer
:initialize_whiny_nils
do
require
(
'active_support/whiny_nil'
)
if
config
.
whiny_nils
end
# Sets the default value for Time.zone
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
initializer
:initialize_time_zone
do
require
'active_support/core_ext/time/zones'
zone_default
=
Time
.
__send__
(
:get_zone
,
config
.
time_zone
)
unless
zone_default
raise
\
'Value assigned to config.time_zone not recognized.'
+
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
end
Time
.
zone_default
=
zone_default
end
# Set the i18n configuration from config.i18n but special-case for the load_path which should be
# appended to what's already set instead of overwritten.
initializer
:initialize_i18n
do
config
.
i18n
.
each
do
|
setting
,
value
|
if
setting
==
:load_path
I18n
.
load_path
+=
value
else
I18n
.
send
(
"
#{
setting
}
="
,
value
)
end
end
end
# # bail out if gems are missing - note that check_gem_dependencies will have
# # already called abort() unless $gems_rake_task is set
# return unless gems_dependencies_loaded
...
...
railties/lib/rails/bootstrap.rb
0 → 100644
浏览文件 @
8fe66f1a
module
Rails
class
Bootstrap
#< Railtie
include
Initializable
def
initialize
(
application
)
@application
=
application
end
delegate
:config
,
:root
,
:to
=>
:'@application'
initializer
:load_all_active_support
do
require
"active_support/all"
unless
config
.
active_support
.
bare
end
# Set the <tt>$LOAD_PATH</tt> based on the value of
# Configuration#load_paths. Duplicates are removed.
initializer
:set_load_path
do
config
.
paths
.
add_to_load_path
$LOAD_PATH
.
uniq!
end
# Set the paths from which Rails will automatically load source files, and
# the load_once paths.
initializer
:set_autoload_paths
do
require
'active_support/dependencies'
ActiveSupport
::
Dependencies
.
load_paths
=
config
.
load_paths
.
uniq
ActiveSupport
::
Dependencies
.
load_once_paths
=
config
.
load_once_paths
.
uniq
extra
=
ActiveSupport
::
Dependencies
.
load_once_paths
-
ActiveSupport
::
Dependencies
.
load_paths
unless
extra
.
empty?
abort
<<-
end_error
load_once_paths must be a subset of the load_paths.
Extra items in load_once_paths:
#{
extra
*
','
}
end_error
end
# Freeze the arrays so future modifications will fail rather than do nothing mysteriously
config
.
load_once_paths
.
freeze
end
# Create tmp directories
initializer
:ensure_tmp_directories_exist
do
%w(cache pids sessions sockets)
.
each
do
|
dir_to_make
|
FileUtils
.
mkdir_p
(
File
.
join
(
root
,
'tmp'
,
dir_to_make
))
end
end
# Preload all frameworks specified by the Configuration#frameworks.
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
initializer
:preload_frameworks
do
ActiveSupport
::
Autoload
.
eager_autoload!
if
config
.
preload_frameworks
end
initializer
:initialize_cache
do
unless
defined?
(
RAILS_CACHE
)
silence_warnings
{
Object
.
const_set
"RAILS_CACHE"
,
ActiveSupport
::
Cache
.
lookup_store
(
config
.
cache_store
)
}
if
RAILS_CACHE
.
respond_to?
(
:middleware
)
# Insert middleware to setup and teardown local cache for each request
config
.
middleware
.
insert_after
(
:"Rack::Lock"
,
RAILS_CACHE
.
middleware
)
end
end
end
initializer
:initialize_logger
do
# if the environment has explicitly defined a logger, use it
next
if
Rails
.
logger
unless
logger
=
config
.
logger
begin
logger
=
ActiveSupport
::
BufferedLogger
.
new
(
config
.
log_path
)
logger
.
level
=
ActiveSupport
::
BufferedLogger
.
const_get
(
config
.
log_level
.
to_s
.
upcase
)
if
RAILS_ENV
==
"production"
logger
.
auto_flushing
=
false
end
rescue
StandardError
=>
e
logger
=
ActiveSupport
::
BufferedLogger
.
new
(
STDERR
)
logger
.
level
=
ActiveSupport
::
BufferedLogger
::
WARN
logger
.
warn
(
"Rails Error: Unable to access log file. Please ensure that
#{
config
.
log_path
}
exists and is chmod 0666. "
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
)
end
end
# TODO: Why are we silencing warning here?
silence_warnings
{
Object
.
const_set
"RAILS_DEFAULT_LOGGER"
,
logger
}
end
# Sets the logger for Active Record, Action Controller, and Action Mailer
# (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.
initializer
:initialize_framework_logging
do
ActiveSupport
::
Dependencies
.
logger
||=
Rails
.
logger
Rails
.
cache
.
logger
||=
Rails
.
logger
end
# Sets the dependency loading mechanism based on the value of
# Configuration#cache_classes.
initializer
:initialize_dependency_mechanism
do
# TODO: Remove files from the $" and always use require
ActiveSupport
::
Dependencies
.
mechanism
=
config
.
cache_classes
?
:require
:
:load
end
# Loads support for "whiny nil" (noisy warnings when methods are invoked
# on +nil+ values) if Configuration#whiny_nils is true.
initializer
:initialize_whiny_nils
do
require
(
'active_support/whiny_nil'
)
if
config
.
whiny_nils
end
# Sets the default value for Time.zone
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
initializer
:initialize_time_zone
do
require
'active_support/core_ext/time/zones'
zone_default
=
Time
.
__send__
(
:get_zone
,
config
.
time_zone
)
unless
zone_default
raise
\
'Value assigned to config.time_zone not recognized.'
+
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
end
Time
.
zone_default
=
zone_default
end
# Set the i18n configuration from config.i18n but special-case for the load_path which should be
# appended to what's already set instead of overwritten.
initializer
:initialize_i18n
do
config
.
i18n
.
each
do
|
setting
,
value
|
if
setting
==
:load_path
I18n
.
load_path
+=
value
else
I18n
.
send
(
"
#{
setting
}
="
,
value
)
end
end
end
end
end
railties/test/application/initializer_test.rb
浏览文件 @
8fe66f1a
...
...
@@ -83,6 +83,17 @@ module Zoo::ReptileHouse ; end
assert_equal
"congratulations"
,
$test_after_initialize_block2
end
test
"after_initialize runs after frameworks have been initialized"
do
$activerecord_configurations
=
nil
add_to_config
<<-
RUBY
config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations }
RUBY
require
"
#{
app_path
}
/config/environment"
assert
$activerecord_configurations
assert
$activerecord_configurations
[
'development'
]
end
# i18n
test
"setting another default locale"
do
add_to_config
<<-
RUBY
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录