Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6f83a503
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,发现更多精彩内容 >>
提交
6f83a503
编写于
6月 22, 2010
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renames load_(once_)paths to autoload_(once_)paths in dependencies and config
上级
4a0a640d
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
59 addition
and
54 deletion
+59
-54
activesupport/CHANGELOG
activesupport/CHANGELOG
+2
-0
activesupport/lib/active_support/dependencies.rb
activesupport/lib/active_support/dependencies.rb
+12
-12
activesupport/test/dependencies_test.rb
activesupport/test/dependencies_test.rb
+18
-18
railties/CHANGELOG
railties/CHANGELOG
+3
-0
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+2
-2
railties/lib/rails/application/finisher.rb
railties/lib/rails/application/finisher.rb
+5
-5
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+8
-8
railties/lib/rails/engine/configuration.rb
railties/lib/rails/engine/configuration.rb
+5
-5
railties/lib/rails/generators/rails/app/templates/config/application.rb
...ails/generators/rails/app/templates/config/application.rb
+1
-1
railties/test/generators/actions_test.rb
railties/test/generators/actions_test.rb
+3
-3
未找到文件。
activesupport/CHANGELOG
浏览文件 @
6f83a503
*Rails 3.0.0 [Release Candidate] (unreleased)*
* Renamed ActiveSupport::Dependecies.load_(once_)paths to autoload_(once_)paths. [fxn]
* Added ActiveSupport::FileUpdateChecker to execute a block only if a set of files changed, used by Router and I18n locale files. [José Valim]
* Added ActiveSupport::DescendantsTracker to track descendants with support to constants reloading. [José Valim]
...
...
activesupport/lib/active_support/dependencies.rb
浏览文件 @
6f83a503
...
...
@@ -33,14 +33,14 @@ module Dependencies #:nodoc:
# The set of directories from which we may automatically load files. Files
# under these directories will be reloaded on each request in development mode,
# unless the directory also appears in load_once_paths.
mattr_accessor
:load_paths
self
.
load_paths
=
[]
# unless the directory also appears in
auto
load_once_paths.
mattr_accessor
:
auto
load_paths
self
.
auto
load_paths
=
[]
# The set of directories from which automatically loaded constants are loaded
# only once. All directories in this set must also be present in +load_paths+.
mattr_accessor
:load_once_paths
self
.
load_once_paths
=
[]
# only once. All directories in this set must also be present in +
auto
load_paths+.
mattr_accessor
:
auto
load_once_paths
self
.
auto
load_once_paths
=
[]
# An array of qualified constant names that have been loaded. Adding a name to
# this array will cause it to be unloaded the next time Dependencies are cleared.
...
...
@@ -352,7 +352,7 @@ def local_const_defined?(mod, const) #:nodoc:
# Given +path+, a filesystem path to a ruby file, return an array of constant
# paths which would cause Dependencies to attempt to load this file.
def
loadable_constants_for_path
(
path
,
bases
=
load_paths
)
def
loadable_constants_for_path
(
path
,
bases
=
auto
load_paths
)
expanded_path
=
Pathname
.
new
(
path
[
/\A(.*?)(\.rb)?\Z/
,
1
]).
expand_path
bases
.
inject
([])
do
|
paths
,
root
|
...
...
@@ -363,11 +363,11 @@ def loadable_constants_for_path(path, bases = load_paths)
end
.
uniq
end
# Search for a file in load_paths matching the provided suffix.
# Search for a file in
auto
load_paths matching the provided suffix.
def
search_for_file
(
path_suffix
)
path_suffix
=
path_suffix
.
sub
(
/(\.rb)?$/
,
".rb"
)
load_paths
.
each
do
|
root
|
auto
load_paths
.
each
do
|
root
|
path
=
File
.
join
(
root
,
path_suffix
)
return
path
if
File
.
file?
path
end
...
...
@@ -377,14 +377,14 @@ def search_for_file(path_suffix)
# Does the provided path_suffix correspond to an autoloadable module?
# Instead of returning a boolean, the autoload base for this module is returned.
def
autoloadable_module?
(
path_suffix
)
load_paths
.
each
do
|
load_path
|
auto
load_paths
.
each
do
|
load_path
|
return
load_path
if
File
.
directory?
File
.
join
(
load_path
,
path_suffix
)
end
nil
end
def
load_once_path?
(
path
)
load_once_paths
.
any?
{
|
base
|
path
.
starts_with?
base
}
auto
load_once_paths
.
any?
{
|
base
|
path
.
starts_with?
base
}
end
# Attempt to autoload the provided module name by searching for a directory
...
...
@@ -396,7 +396,7 @@ def autoload_module!(into, const_name, qualified_name, path_suffix)
return
nil
unless
base_path
=
autoloadable_module?
(
path_suffix
)
mod
=
Module
.
new
into
.
const_set
const_name
,
mod
autoloaded_constants
<<
qualified_name
unless
load_once_paths
.
include?
(
base_path
)
autoloaded_constants
<<
qualified_name
unless
auto
load_once_paths
.
include?
(
base_path
)
return
mod
end
...
...
activesupport/test/dependencies_test.rb
浏览文件 @
6f83a503
...
...
@@ -25,11 +25,11 @@ def with_loading(*from)
this_dir
=
File
.
dirname
(
__FILE__
)
parent_dir
=
File
.
dirname
(
this_dir
)
$LOAD_PATH
.
unshift
(
parent_dir
)
unless
$LOAD_PATH
.
include?
(
parent_dir
)
prior_
load_paths
=
ActiveSupport
::
Dependencies
.
load_paths
ActiveSupport
::
Dependencies
.
load_paths
=
from
.
collect
{
|
f
|
"
#{
this_dir
}
/
#{
f
}
"
}
prior_
autoload_paths
=
ActiveSupport
::
Dependencies
.
auto
load_paths
ActiveSupport
::
Dependencies
.
auto
load_paths
=
from
.
collect
{
|
f
|
"
#{
this_dir
}
/
#{
f
}
"
}
yield
ensure
ActiveSupport
::
Dependencies
.
load_paths
=
prior_
load_paths
ActiveSupport
::
Dependencies
.
autoload_paths
=
prior_auto
load_paths
ActiveSupport
::
Dependencies
.
mechanism
=
old_mechanism
ActiveSupport
::
Dependencies
.
explicitly_unloadable_constants
=
[]
end
...
...
@@ -264,7 +264,7 @@ def test_loadable_constants_for_path_should_handle_relative_paths
def
test_loadable_constants_for_path_should_provide_all_results
fake_root
=
'/usr/apps/backpack'
with_loading
fake_root
,
fake_root
+
'/lib'
do
root
=
ActiveSupport
::
Dependencies
.
load_paths
.
first
root
=
ActiveSupport
::
Dependencies
.
auto
load_paths
.
first
assert_equal
[
"Lib::A::B"
,
"A::B"
],
ActiveSupport
::
Dependencies
.
loadable_constants_for_path
(
root
+
'/lib/a/b'
)
end
end
...
...
@@ -272,7 +272,7 @@ def test_loadable_constants_for_path_should_provide_all_results
def
test_loadable_constants_for_path_should_uniq_results
fake_root
=
'/usr/apps/backpack/lib'
with_loading
fake_root
,
fake_root
+
'/'
do
root
=
ActiveSupport
::
Dependencies
.
load_paths
.
first
root
=
ActiveSupport
::
Dependencies
.
auto
load_paths
.
first
assert_equal
[
"A::B"
],
ActiveSupport
::
Dependencies
.
loadable_constants_for_path
(
root
+
'/a/b'
)
end
end
...
...
@@ -344,7 +344,7 @@ def test_qualified_name_for
def
test_file_search
with_loading
'dependencies'
do
root
=
ActiveSupport
::
Dependencies
.
load_paths
.
first
root
=
ActiveSupport
::
Dependencies
.
auto
load_paths
.
first
assert_equal
nil
,
ActiveSupport
::
Dependencies
.
search_for_file
(
'service_three'
)
assert_equal
nil
,
ActiveSupport
::
Dependencies
.
search_for_file
(
'service_three.rb'
)
assert_equal
root
+
'/service_one.rb'
,
ActiveSupport
::
Dependencies
.
search_for_file
(
'service_one'
)
...
...
@@ -354,14 +354,14 @@ def test_file_search
def
test_file_search_uses_first_in_load_path
with_loading
'dependencies'
,
'autoloading_fixtures'
do
deps
,
autoload
=
ActiveSupport
::
Dependencies
.
load_paths
deps
,
autoload
=
ActiveSupport
::
Dependencies
.
auto
load_paths
assert_match
%r/dependencies/
,
deps
assert_match
%r/autoloading_fixtures/
,
autoload
assert_equal
deps
+
'/conflict.rb'
,
ActiveSupport
::
Dependencies
.
search_for_file
(
'conflict'
)
end
with_loading
'autoloading_fixtures'
,
'dependencies'
do
autoload
,
deps
=
ActiveSupport
::
Dependencies
.
load_paths
autoload
,
deps
=
ActiveSupport
::
Dependencies
.
auto
load_paths
assert_match
%r/dependencies/
,
deps
assert_match
%r/autoloading_fixtures/
,
autoload
...
...
@@ -418,7 +418,7 @@ def test_const_missing_within_anonymous_module
def
test_removal_from_tree_should_be_detected
with_loading
'dependencies'
do
root
=
ActiveSupport
::
Dependencies
.
load_paths
.
first
root
=
ActiveSupport
::
Dependencies
.
auto
load_paths
.
first
c
=
ServiceOne
ActiveSupport
::
Dependencies
.
clear
assert
!
defined?
(
ServiceOne
)
...
...
@@ -433,7 +433,7 @@ def test_removal_from_tree_should_be_detected
def
test_references_should_work
with_loading
'dependencies'
do
root
=
ActiveSupport
::
Dependencies
.
load_paths
.
first
root
=
ActiveSupport
::
Dependencies
.
auto
load_paths
.
first
c
=
ActiveSupport
::
Dependencies
.
ref
(
"ServiceOne"
)
service_one_first
=
ServiceOne
assert_equal
service_one_first
,
c
.
get
...
...
@@ -460,9 +460,9 @@ def test_nested_load_error_isnt_rescued
end
end
def
test_load_once_paths_do_not_add_to_autoloaded_constants
def
test_
auto
load_once_paths_do_not_add_to_autoloaded_constants
with_autoloading_fixtures
do
ActiveSupport
::
Dependencies
.
load_once_paths
=
ActiveSupport
::
Dependencies
.
load_paths
.
dup
ActiveSupport
::
Dependencies
.
autoload_once_paths
=
ActiveSupport
::
Dependencies
.
auto
load_paths
.
dup
assert
!
ActiveSupport
::
Dependencies
.
autoloaded?
(
"ModuleFolder"
)
assert
!
ActiveSupport
::
Dependencies
.
autoloaded?
(
"ModuleFolder::NestedClass"
)
...
...
@@ -473,7 +473,7 @@ def test_load_once_paths_do_not_add_to_autoloaded_constants
end
ensure
Object
.
class_eval
{
remove_const
:ModuleFolder
}
ActiveSupport
::
Dependencies
.
load_once_paths
=
[]
ActiveSupport
::
Dependencies
.
auto
load_once_paths
=
[]
end
def
test_application_should_special_case_application_controller
...
...
@@ -760,20 +760,20 @@ def test_remove_constant_handles_double_colon_at_start
def
test_load_once_constants_should_not_be_unloaded
with_autoloading_fixtures
do
ActiveSupport
::
Dependencies
.
load_once_paths
=
ActiveSupport
::
Dependencies
.
load_paths
ActiveSupport
::
Dependencies
.
autoload_once_paths
=
ActiveSupport
::
Dependencies
.
auto
load_paths
::
A
.
to_s
assert
defined?
(
A
)
ActiveSupport
::
Dependencies
.
clear
assert
defined?
(
A
)
end
ensure
ActiveSupport
::
Dependencies
.
load_once_paths
=
[]
ActiveSupport
::
Dependencies
.
auto
load_once_paths
=
[]
Object
.
class_eval
{
remove_const
:A
if
const_defined?
(
:A
)
}
end
def
test_load_once_paths_should_behave_when_recursively_loading
def
test_
auto
load_once_paths_should_behave_when_recursively_loading
with_loading
'dependencies'
,
'autoloading_fixtures'
do
ActiveSupport
::
Dependencies
.
load_once_paths
=
[
ActiveSupport
::
Dependencies
.
load_paths
.
last
]
ActiveSupport
::
Dependencies
.
autoload_once_paths
=
[
ActiveSupport
::
Dependencies
.
auto
load_paths
.
last
]
assert
!
defined?
(
CrossSiteDependency
)
assert_nothing_raised
{
CrossSiteDepender
.
nil?
}
assert
defined?
(
CrossSiteDependency
)
...
...
@@ -784,7 +784,7 @@ def test_load_once_paths_should_behave_when_recursively_loading
"CrossSiteDependency shouldn't have been unloaded!"
end
ensure
ActiveSupport
::
Dependencies
.
load_once_paths
=
[]
ActiveSupport
::
Dependencies
.
auto
load_once_paths
=
[]
end
def
test_hook_called_multiple_times
...
...
railties/CHANGELOG
浏览文件 @
6f83a503
*Rails 3.0.0 [Release Candidate] (unreleased)*
* config.load_(once_)paths in config/application.rb got renamed to config.autoload_(once_)paths. [fxn]
* Abort generation/booting on Ruby 1.9.1. [fxn]
* Made the rails command work even when you're in a subdirectory [Chad Fowler]
...
...
railties/lib/rails/application.rb
浏览文件 @
6f83a503
...
...
@@ -67,7 +67,7 @@ def inherited(base)
raise
"You cannot have more than one Rails::Application"
if
Rails
.
application
super
Rails
.
application
=
base
.
instance
Rails
.
application
.
add_lib_to_load_path
s
!
Rails
.
application
.
add_lib_to_load_path!
ActiveSupport
.
run_load_hooks
(
:before_configuration
,
base
.
instance
)
end
...
...
@@ -97,7 +97,7 @@ def method_missing(*args, &block)
# are changing config.root inside your application definition or having a custom
# Rails application, you will need to add lib to $LOAD_PATH on your own in case
# you need to load files in lib/ during the application configuration as well.
def
add_lib_to_load_path
s
!
#:nodoc:
def
add_lib_to_load_path!
#:nodoc:
path
=
config
.
root
.
join
(
'lib'
).
to_s
$LOAD_PATH
.
unshift
(
path
)
if
File
.
exists?
(
path
)
end
...
...
railties/lib/rails/application/finisher.rb
浏览文件 @
6f83a503
...
...
@@ -7,14 +7,14 @@ module Finisher
config
.
generators
.
templates
.
unshift
(
*
paths
.
lib
.
templates
.
to_a
)
end
initializer
:ensure_load_once_paths_as_subset
do
extra
=
ActiveSupport
::
Dependencies
.
load_once_paths
-
ActiveSupport
::
Dependencies
.
load_paths
initializer
:ensure_
auto
load_once_paths_as_subset
do
extra
=
ActiveSupport
::
Dependencies
.
auto
load_once_paths
-
ActiveSupport
::
Dependencies
.
auto
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
*
','
}
autoload_once_paths must be a subset of the auto
load_paths.
Extra items in
auto
load_once_paths:
#{
extra
*
','
}
end_error
end
end
...
...
railties/lib/rails/engine.rb
浏览文件 @
6f83a503
...
...
@@ -32,14 +32,14 @@ module Rails
# == Configuration
#
# Besides the Railtie configuration which is shared across the application, in a
# Rails::Engine you can access
load_paths, eager_load_paths and
load_once_paths,
# Rails::Engine you can access
autoload_paths, eager_load_paths and auto
load_once_paths,
# which differently from a Railtie, are scoped to the current Engine.
#
# Example:
#
# class MyEngine < Rails::Engine
# # Add a load path for this specific Engine
# config.load_paths << File.expand_path("../lib/some/path", __FILE__)
# config.
auto
load_paths << File.expand_path("../lib/some/path", __FILE__)
#
# initializer "my_engine.add_middleware" do |app|
# app.middleware.use MyEngine::Middleware
...
...
@@ -142,7 +142,7 @@ def eager_load!
# Add configured load paths to ruby load paths and remove duplicates.
initializer
:set_load_path
,
:before
=>
:bootstrap_hook
do
config
.
load_paths
.
reverse_each
do
|
path
|
config
.
auto
load_paths
.
reverse_each
do
|
path
|
$LOAD_PATH
.
unshift
(
path
)
if
File
.
directory?
(
path
)
end
$LOAD_PATH
.
uniq!
...
...
@@ -154,17 +154,17 @@ def eager_load!
# This needs to be an initializer, since it needs to run once
# per engine and get the engine as a block parameter
initializer
:set_autoload_paths
,
:before
=>
:bootstrap_hook
do
|
app
|
ActiveSupport
::
Dependencies
.
load_paths
.
unshift
(
*
config
.
load_paths
)
ActiveSupport
::
Dependencies
.
autoload_paths
.
unshift
(
*
config
.
auto
load_paths
)
if
reloadable?
(
app
)
ActiveSupport
::
Dependencies
.
load_once_paths
.
unshift
(
*
config
.
load_once_paths
)
ActiveSupport
::
Dependencies
.
autoload_once_paths
.
unshift
(
*
config
.
auto
load_once_paths
)
else
ActiveSupport
::
Dependencies
.
load_once_paths
.
unshift
(
*
config
.
load_paths
)
ActiveSupport
::
Dependencies
.
autoload_once_paths
.
unshift
(
*
config
.
auto
load_paths
)
end
# Freeze so future modifications will fail rather than do nothing mysteriously
config
.
load_paths
.
freeze
config
.
load_once_paths
.
freeze
config
.
auto
load_paths
.
freeze
config
.
auto
load_once_paths
.
freeze
end
initializer
:add_routing_paths
do
|
app
|
...
...
railties/lib/rails/engine/configuration.rb
浏览文件 @
6f83a503
...
...
@@ -4,7 +4,7 @@ module Rails
class
Engine
class
Configuration
<
::
Rails
::
Railtie
::
Configuration
attr_reader
:root
attr_writer
:eager_load_paths
,
:
load_once_paths
,
:
load_paths
attr_writer
:eager_load_paths
,
:
autoload_once_paths
,
:auto
load_paths
def
initialize
(
root
=
nil
)
super
()
...
...
@@ -41,12 +41,12 @@ def eager_load_paths
@eager_load_paths
||=
paths
.
eager_load
end
def
load_once_paths
@load_once_paths
||=
paths
.
load_once
def
auto
load_once_paths
@
auto
load_once_paths
||=
paths
.
load_once
end
def
load_paths
@load_paths
||=
paths
.
load_paths
def
auto
load_paths
@
auto
load_paths
||=
paths
.
load_paths
end
end
end
...
...
railties/lib/rails/generators/rails/app/templates/config/application.rb
浏览文件 @
6f83a503
...
...
@@ -22,7 +22,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{config.root}/extras )
# config.
auto
load_paths += %W( #{config.root}/extras )
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
...
...
railties/test/generators/actions_test.rb
浏览文件 @
6f83a503
...
...
@@ -130,9 +130,9 @@ def test_gem_should_insert_on_separate_lines
def
test_environment_should_include_data_in_environment_initializer_block
run_generator
load_paths
=
'config.
load_paths += %w["#{Rails.root}/app/extras"]'
action
:environment
,
load_paths
assert_file
'config/application.rb'
,
/
#{
Regexp
.
escape
(
load_paths
)
}
/
autoload_paths
=
'config.auto
load_paths += %w["#{Rails.root}/app/extras"]'
action
:environment
,
auto
load_paths
assert_file
'config/application.rb'
,
/
#{
Regexp
.
escape
(
auto
load_paths
)
}
/
end
def
test_environment_with_block_should_include_block_contents_in_environment_initializer_block
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录