Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1c67ecca
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,体验更适合开发者的 AI 搜索 >>
提交
1c67ecca
编写于
4月 10, 2013
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10157 from prathamesh-sonpatki/app_loader
Searching for rails executable correctly
上级
4658b0d4
22e5ab31
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
19 deletion
+14
-19
railties/lib/rails/app_rails_loader.rb
railties/lib/rails/app_rails_loader.rb
+11
-16
railties/test/app_rails_loader_test.rb
railties/test/app_rails_loader_test.rb
+3
-3
未找到文件。
railties/lib/rails/app_rails_loader.rb
浏览文件 @
1c67ecca
...
...
@@ -6,22 +6,22 @@ module AppRailsLoader
EXECUTABLES
=
[
'bin/rails'
,
'script/rails'
]
def
self
.
exec_app_rails
cwd
=
Dir
.
pwd
exe
=
find_executable
exe
||=
find_executable_in_parent_path
return
unless
exe
cwd
=
Dir
.
pwd
pathname
=
Pathname
.
new
(
Dir
.
pwd
)
until
exe
=
find_executable
# Return to working directory if root is hit without finding executable
Dir
.
chdir
(
cwd
)
and
return
if
pathname
.
root?
# Otherwise keep moving upwards in search of executable
Dir
.
chdir
(
".."
)
pathname
=
pathname
.
parent
end
contents
=
File
.
read
(
exe
)
# This is the Rails executable, let's use it
if
contents
=~
/(APP|ENGINE)_PATH/
exec
RUBY
,
exe
,
*
ARGV
if
find_executable
Dir
.
chdir
(
".."
)
do
# Recurse in a chdir block: if the search fails we want to be sure
# the application is generated in the original working directory.
exec_app_rails
unless
cwd
==
Dir
.
pwd
end
exec
RUBY
,
exe
,
*
ARGV
# This is a Bundler binstub. Stop and explain how to upgrade.
elsif
exe
=~
/bin\/rails$/
&&
contents
=~
/This file was generated by Bundler/
...
...
@@ -59,10 +59,5 @@ def self.find_executable
EXECUTABLES
.
find
{
|
exe
|
File
.
exists?
(
exe
)
}
end
def
self
.
find_executable_in_parent_path
(
path
=
Pathname
.
new
(
Dir
.
pwd
).
parent
)
EXECUTABLES
.
find
do
|
exe
|
File
.
exists?
(
exe
)
||
!
path
.
root?
&&
find_executable_in_parent_path
(
path
.
parent
)
end
end
end
end
railties/test/app_rails_loader_test.rb
浏览文件 @
1c67ecca
...
...
@@ -17,14 +17,14 @@ class AppRailsLoaderTest < ActiveSupport::TestCase
test
"is not in a rails application if
#{
exe
}
exists but doesn't contain APP_PATH"
do
File
.
stubs
(
:exists?
).
with
(
exe
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
exe
).
returns
(
"railties
#{
exe
}
"
)
assert
!
Rails
::
AppRailsLoader
.
find_executable
assert
!
Rails
::
AppRailsLoader
.
exec_app_rails
end
test
"is in a rails application if parent directory has
#{
exe
}
containing APP_PATH"
do
File
.
stubs
(
:exists?
).
with
(
"/foo/bar/
#{
exe
}
"
).
returns
(
false
)
File
.
stubs
(
:exists?
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
'APP_PATH'
)
assert
Rails
::
AppRailsLoader
.
find_executable_in_parent_path
(
Pathname
.
new
(
"/foo/bar"
))
assert
_equal
Rails
::
AppRailsLoader
.
find_executable_in_parent_path
(
Pathname
.
new
(
"/foo/bar"
)),
"/foo/
#{
exe
}
"
end
test
"is not in a rails application if at the root directory and doesn't have
#{
exe
}
"
do
...
...
@@ -36,7 +36,7 @@ class AppRailsLoaderTest < ActiveSupport::TestCase
File
.
stubs
(
:exists?
).
with
(
"/foo/bar/
#{
exe
}
"
).
returns
(
false
)
File
.
stubs
(
:exists?
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
'ENGINE_PATH'
)
assert
Rails
::
AppRailsLoader
.
find_executable_in_parent_path
(
Pathname
.
new
(
"/foo/bar"
))
assert
Rails
::
AppRailsLoader
.
find_executable_in_parent_path
(
Pathname
.
new
(
"/foo/bar"
))
,
"/foo/
#{
exe
}
"
end
test
"is in a rails engine if
#{
exe
}
exists containing ENGINE_PATH"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录