Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9a42e06d
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,发现更多精彩内容 >>
提交
9a42e06d
编写于
7月 06, 2009
作者:
Y
Yehuda Katz + Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reapply Rails::Application::Path tweaks
Reapplies:
a4bdc00f
3c1dab72
上级
783db25e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
126 addition
and
46 deletion
+126
-46
railties/lib/rails/configuration.rb
railties/lib/rails/configuration.rb
+13
-27
railties/lib/rails/paths.rb
railties/lib/rails/paths.rb
+25
-15
railties/test/paths_test.rb
railties/test/paths_test.rb
+88
-4
未找到文件。
railties/lib/rails/configuration.rb
浏览文件 @
9a42e06d
...
@@ -62,33 +62,19 @@ def set_root_path!
...
@@ -62,33 +62,19 @@ def set_root_path!
end
end
@paths
=
Rails
::
Application
::
Root
.
new
(
root_path
)
@paths
=
Rails
::
Application
::
Root
.
new
(
root_path
)
@paths
.
app
=
"app"
@paths
.
app
"app"
,
:load_path
=>
true
@paths
.
app
.
metals
=
"app/metal"
@paths
.
app
.
metals
"app/metal"
,
:eager_load
=>
true
@paths
.
app
.
models
=
"app/models"
@paths
.
app
.
models
"app/models"
,
:eager_load
=>
true
@paths
.
app
.
controllers
=
"app/controllers"
@paths
.
app
.
controllers
"app/controllers"
,
builtin_directories
,
:eager_load
=>
true
@paths
.
app
.
helpers
=
"app/helpers"
@paths
.
app
.
helpers
"app/helpers"
,
:eager_load
=>
true
@paths
.
app
.
services
=
"app/services"
@paths
.
app
.
services
"app/services"
,
:load_path
=>
true
@paths
.
lib
=
"lib"
@paths
.
lib
"lib"
,
:load_path
=>
true
@paths
.
vendor
=
"vendor"
@paths
.
vendor
"vendor"
,
:load_path
=>
true
@paths
.
vendor
.
plugins
=
"vendor/plugins"
@paths
.
vendor
.
plugins
"vendor/plugins"
@paths
.
cache
=
"tmp/cache"
@paths
.
cache
"tmp/cache"
@paths
.
config
=
"config"
@paths
.
config
"config"
@paths
.
config
.
locales
=
"config/locales"
@paths
.
config
.
locales
"config/locales"
@paths
.
config
.
environments
=
"config/environments"
@paths
.
config
.
environments
"config/environments"
,
:glob
=>
"
#{
RAILS_ENV
}
.rb"
@paths
.
app
.
controllers
.
concat
builtin_directories
@paths
.
app
.
load_path!
@paths
.
app
.
metals
.
load_path!
@paths
.
app
.
models
.
eager_load!
@paths
.
app
.
controllers
.
eager_load!
@paths
.
app
.
helpers
.
eager_load!
@paths
.
app
.
services
.
load_path!
@paths
.
app
.
metals
.
eager_load!
@paths
.
lib
.
load_path!
@paths
.
vendor
.
load_path!
@paths
.
config
.
environments
.
glob
=
"
#{
RAILS_ENV
}
.rb"
RAILS_ROOT
.
replace
root_path
RAILS_ROOT
.
replace
root_path
end
end
...
...
railties/lib/rails/paths.rb
浏览文件 @
9a42e06d
...
@@ -6,8 +6,8 @@ module PathParent
...
@@ -6,8 +6,8 @@ module PathParent
def
method_missing
(
id
,
*
args
)
def
method_missing
(
id
,
*
args
)
name
=
id
.
to_s
name
=
id
.
to_s
if
name
=~
/^(.*)=$/
if
name
=~
/^(.*)=$/
||
args
.
any?
@children
[
$1
]
=
Path
.
new
(
args
.
first
,
@root
)
@children
[
$1
||
name
]
=
Path
.
new
(
@root
,
*
args
)
elsif
path
=
@children
[
name
]
elsif
path
=
@children
[
name
]
path
path
else
else
...
@@ -28,17 +28,15 @@ def initialize(path)
...
@@ -28,17 +28,15 @@ def initialize(path)
# TODO: Move logic from set_root_path initializer
# TODO: Move logic from set_root_path initializer
@path
=
File
.
expand_path
(
path
)
@path
=
File
.
expand_path
(
path
)
@root
=
self
@root
=
self
@
load_once
,
@eager_load
,
@all_paths
=
[],
[],
[]
@
all_paths
=
[]
end
end
def
load_once
def
load_once
@load_once
.
uniq!
all_paths
.
map
{
|
path
|
path
.
paths
if
path
.
load_once?
}.
compact
.
flatten
.
uniq
@load_once
end
end
def
eager_load
def
eager_load
@eager_load
.
uniq!
all_paths
.
map
{
|
path
|
path
.
paths
if
path
.
eager_load?
}.
compact
.
flatten
.
uniq
@eager_load
end
end
def
all_paths
def
all_paths
...
@@ -47,7 +45,7 @@ def all_paths
...
@@ -47,7 +45,7 @@ def all_paths
end
end
def
load_paths
def
load_paths
all_paths
.
map
{
|
path
|
path
.
paths
}.
flatten
all_paths
.
map
{
|
path
|
path
.
paths
if
path
.
load_path?
}.
compact
.
flatten
.
uniq
end
end
def
add_to_load_path
def
add_to_load_path
...
@@ -55,6 +53,14 @@ def add_to_load_path
...
@@ -55,6 +53,14 @@ def add_to_load_path
$LOAD_PATH
.
unshift
(
path
)
if
File
.
directory?
(
path
)
$LOAD_PATH
.
unshift
(
path
)
if
File
.
directory?
(
path
)
end
end
end
end
def
push
(
*
)
raise
"Application root can only have one physical path"
end
alias
unshift
push
alias
<<
push
alias
concat
push
end
end
class
Path
class
Path
...
@@ -63,11 +69,18 @@ class Path
...
@@ -63,11 +69,18 @@ class Path
attr_reader
:path
attr_reader
:path
attr_accessor
:glob
attr_accessor
:glob
def
initialize
(
path
,
root
)
def
initialize
(
root
,
*
paths
)
@options
=
paths
.
last
.
is_a?
(
::
Hash
)
?
paths
.
pop
:
{}
@children
=
{}
@children
=
{}
@root
=
root
@root
=
root
@paths
=
[
path
].
flatten
@paths
=
paths
.
flatten
@glob
=
"**/*.rb"
@glob
=
@options
[
:glob
]
||
"**/*.rb"
@load_once
=
@options
[
:load_once
]
@eager_load
=
@options
[
:eager_load
]
@load_path
=
@options
[
:load_path
]
||
@eager_load
@root
.
all_paths
<<
self
end
end
def
push
(
path
)
def
push
(
path
)
...
@@ -86,7 +99,6 @@ def concat(paths)
...
@@ -86,7 +99,6 @@ def concat(paths)
def
load_once!
def
load_once!
@load_once
=
true
@load_once
=
true
@root
.
load_once
.
push
*
self
.
paths
end
end
def
load_once?
def
load_once?
...
@@ -95,8 +107,7 @@ def load_once?
...
@@ -95,8 +107,7 @@ def load_once?
def
eager_load!
def
eager_load!
@eager_load
=
true
@eager_load
=
true
@root
.
all_paths
<<
self
@load_path
=
true
@root
.
eager_load
.
push
*
self
.
paths
end
end
def
eager_load?
def
eager_load?
...
@@ -105,7 +116,6 @@ def eager_load?
...
@@ -105,7 +116,6 @@ def eager_load?
def
load_path!
def
load_path!
@load_path
=
true
@load_path
=
true
@root
.
all_paths
<<
self
end
end
def
load_path?
def
load_path?
...
...
railties/test/paths_test.rb
浏览文件 @
9a42e06d
...
@@ -17,17 +17,37 @@ def setup
...
@@ -17,17 +17,37 @@ def setup
assert_equal
[
"/foo/bar"
],
@root
.
app
.
to_a
assert_equal
[
"/foo/bar"
],
@root
.
app
.
to_a
end
end
test
"creating a root level path without assignment"
do
@root
.
app
"/foo/bar"
assert_equal
[
"/foo/bar"
],
@root
.
app
.
to_a
end
test
"trying to access a path that does not exist raises NoMethodError"
do
assert_raises
(
NoMethodError
)
{
@root
.
app
}
end
test
"relative paths are relative to the paths root"
do
test
"relative paths are relative to the paths root"
do
@root
.
app
=
"app"
@root
.
app
=
"app"
assert_equal
[
"/foo/bar/app"
],
@root
.
app
.
to_a
assert_equal
[
"/foo/bar/app"
],
@root
.
app
.
to_a
end
end
test
"relative paths are relative to the paths root without assignment"
do
@root
.
app
"app"
assert_equal
[
"/foo/bar/app"
],
@root
.
app
.
to_a
end
test
"creating a child level path"
do
test
"creating a child level path"
do
@root
.
app
=
"/foo/bar"
@root
.
app
=
"/foo/bar"
@root
.
app
.
models
=
"/foo/bar/baz"
@root
.
app
.
models
=
"/foo/bar/baz"
assert_equal
[
"/foo/bar/baz"
],
@root
.
app
.
models
.
to_a
assert_equal
[
"/foo/bar/baz"
],
@root
.
app
.
models
.
to_a
end
end
test
"creating a child level path without assignment"
do
@root
.
app
=
"/foo/bar"
@root
.
app
.
models
"/foo/bar/baz"
assert_equal
[
"/foo/bar/baz"
],
@root
.
app
.
models
.
to_a
end
test
"child level paths are relative from the root"
do
test
"child level paths are relative from the root"
do
@root
.
app
=
"/app"
@root
.
app
=
"/app"
@root
.
app
.
models
=
"baz"
@root
.
app
.
models
=
"baz"
...
@@ -40,6 +60,11 @@ def setup
...
@@ -40,6 +60,11 @@ def setup
assert_equal
[
"/app"
,
"/app2"
],
@root
.
app
.
to_a
assert_equal
[
"/app"
,
"/app2"
],
@root
.
app
.
to_a
end
end
test
"adding multiple physical paths as an array without assignment"
do
@root
.
app
"/app"
,
"/app2"
assert_equal
[
"/app"
,
"/app2"
],
@root
.
app
.
to_a
end
test
"adding multiple physical paths using #push"
do
test
"adding multiple physical paths using #push"
do
@root
.
app
=
"/app"
@root
.
app
=
"/app"
@root
.
app
.
push
"/app2"
@root
.
app
.
push
"/app2"
...
@@ -66,10 +91,10 @@ def setup
...
@@ -66,10 +91,10 @@ def setup
test
"the root can only have one physical path"
do
test
"the root can only have one physical path"
do
assert_raise
(
RuntimeError
)
{
Rails
::
Application
::
Root
.
new
([
"/fiz"
,
"/biz"
])
}
assert_raise
(
RuntimeError
)
{
Rails
::
Application
::
Root
.
new
([
"/fiz"
,
"/biz"
])
}
assert_raise
(
NoMethod
Error
)
{
@root
.
push
"/biz"
}
assert_raise
(
Runtime
Error
)
{
@root
.
push
"/biz"
}
assert_raise
(
NoMethod
Error
)
{
@root
.
unshift
"/biz"
}
assert_raise
(
Runtime
Error
)
{
@root
.
unshift
"/biz"
}
assert_raise
(
NoMethod
Error
)
{
@root
.
concat
[
"/biz"
]}
assert_raise
(
Runtime
Error
)
{
@root
.
concat
[
"/biz"
]}
assert_raise
(
NoMethod
Error
)
{
@root
<<
"/biz"
}
assert_raise
(
Runtime
Error
)
{
@root
<<
"/biz"
}
end
end
test
"it is possible to add a path that should be loaded only once"
do
test
"it is possible to add a path that should be loaded only once"
do
...
@@ -79,6 +104,19 @@ def setup
...
@@ -79,6 +104,19 @@ def setup
assert
@root
.
load_once
.
include?
(
@root
.
app
.
paths
.
first
)
assert
@root
.
load_once
.
include?
(
@root
.
app
.
paths
.
first
)
end
end
test
"it is possible to add a path without assignment and specify it should be loaded only once"
do
@root
.
app
"/app"
,
:load_once
=>
true
assert
@root
.
app
.
load_once?
assert
@root
.
load_once
.
include?
(
"/app"
)
end
test
"it is possible to add multiple paths without assignment and specify it should be loaded only once"
do
@root
.
app
"/app"
,
"/app2"
,
:load_once
=>
true
assert
@root
.
app
.
load_once?
assert
@root
.
load_once
.
include?
(
"/app"
)
assert
@root
.
load_once
.
include?
(
"/app2"
)
end
test
"making a path load_once more than once only includes it once in @root.load_once"
do
test
"making a path load_once more than once only includes it once in @root.load_once"
do
@root
.
app
=
"/app"
@root
.
app
=
"/app"
@root
.
app
.
load_once!
@root
.
app
.
load_once!
...
@@ -86,6 +124,13 @@ def setup
...
@@ -86,6 +124,13 @@ def setup
assert_equal
1
,
@root
.
load_once
.
select
{
|
p
|
p
==
@root
.
app
.
paths
.
first
}.
size
assert_equal
1
,
@root
.
load_once
.
select
{
|
p
|
p
==
@root
.
app
.
paths
.
first
}.
size
end
end
test
"paths added to a load_once path should be added to the load_once collection"
do
@root
.
app
=
"/app"
@root
.
app
.
load_once!
@root
.
app
<<
"/app2"
assert_equal
2
,
@root
.
load_once
.
size
end
test
"it is possible to mark a path as eager"
do
test
"it is possible to mark a path as eager"
do
@root
.
app
=
"/app"
@root
.
app
=
"/app"
@root
.
app
.
eager_load!
@root
.
app
.
eager_load!
...
@@ -93,6 +138,27 @@ def setup
...
@@ -93,6 +138,27 @@ def setup
assert
@root
.
eager_load
.
include?
(
@root
.
app
.
paths
.
first
)
assert
@root
.
eager_load
.
include?
(
@root
.
app
.
paths
.
first
)
end
end
test
"it is possible to add a path without assignment and mark it as eager"
do
@root
.
app
"/app"
,
:eager_load
=>
true
assert
@root
.
app
.
eager_load?
assert
@root
.
eager_load
.
include?
(
"/app"
)
end
test
"it is possible to add multiple paths without assignment and mark them as eager"
do
@root
.
app
"/app"
,
"/app2"
,
:eager_load
=>
true
assert
@root
.
app
.
eager_load?
assert
@root
.
eager_load
.
include?
(
"/app"
)
assert
@root
.
eager_load
.
include?
(
"/app2"
)
end
test
"it is possible to create a path without assignment and mark it both as eager and load once"
do
@root
.
app
"/app"
,
:eager_load
=>
true
,
:load_once
=>
true
assert
@root
.
app
.
eager_load?
assert
@root
.
app
.
load_once?
assert
@root
.
eager_load
.
include?
(
"/app"
)
assert
@root
.
load_once
.
include?
(
"/app"
)
end
test
"making a path eager more than once only includes it once in @root.eager_paths"
do
test
"making a path eager more than once only includes it once in @root.eager_paths"
do
@root
.
app
=
"/app"
@root
.
app
=
"/app"
@root
.
app
.
eager_load!
@root
.
app
.
eager_load!
...
@@ -100,6 +166,13 @@ def setup
...
@@ -100,6 +166,13 @@ def setup
assert_equal
1
,
@root
.
eager_load
.
select
{
|
p
|
p
==
@root
.
app
.
paths
.
first
}.
size
assert_equal
1
,
@root
.
eager_load
.
select
{
|
p
|
p
==
@root
.
app
.
paths
.
first
}.
size
end
end
test
"paths added to a eager_load path should be added to the eager_load collection"
do
@root
.
app
=
"/app"
@root
.
app
.
eager_load!
@root
.
app
<<
"/app2"
assert_equal
2
,
@root
.
eager_load
.
size
end
test
"a path should have a glob that defaults to **/*.rb"
do
test
"a path should have a glob that defaults to **/*.rb"
do
@root
.
app
=
"/app"
@root
.
app
=
"/app"
assert_equal
"**/*.rb"
,
@root
.
app
.
glob
assert_equal
"**/*.rb"
,
@root
.
app
.
glob
...
@@ -111,6 +184,11 @@ def setup
...
@@ -111,6 +184,11 @@ def setup
assert_equal
"*.rb"
,
@root
.
app
.
glob
assert_equal
"*.rb"
,
@root
.
app
.
glob
end
end
test
"it should be possible to override a path's default glob without assignment"
do
@root
.
app
"/app"
,
:glob
=>
"*.rb"
assert_equal
"*.rb"
,
@root
.
app
.
glob
end
test
"a path can be added to the load path"
do
test
"a path can be added to the load path"
do
@root
.
app
=
"app"
@root
.
app
=
"app"
@root
.
app
.
load_path!
@root
.
app
.
load_path!
...
@@ -118,6 +196,12 @@ def setup
...
@@ -118,6 +196,12 @@ def setup
assert_equal
[
"/foo/bar/app"
],
@root
.
load_paths
assert_equal
[
"/foo/bar/app"
],
@root
.
load_paths
end
end
test
"a path can be added to the load path on creation"
do
@root
.
app
"/app"
,
:load_path
=>
true
assert
@root
.
app
.
load_path?
assert_equal
[
"/app"
],
@root
.
load_paths
end
test
"adding a path to the eager paths also adds it to the load path"
do
test
"adding a path to the eager paths also adds it to the load path"
do
@root
.
app
=
"app"
@root
.
app
=
"app"
@root
.
app
.
eager_load!
@root
.
app
.
eager_load!
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录