Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f8e7904d
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,发现更多精彩内容 >>
提交
f8e7904d
编写于
5月 29, 2012
作者:
K
kennyj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support runner hook.
上级
5cc9c7e3
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
53 addition
and
0 deletion
+53
-0
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+11
-0
railties/lib/rails/commands/runner.rb
railties/lib/rails/commands/runner.rb
+1
-0
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+5
-0
railties/lib/rails/railtie.rb
railties/lib/rails/railtie.rb
+10
-0
railties/test/application/runner_test.rb
railties/test/application/runner_test.rb
+10
-0
railties/test/railties/railtie_test.rb
railties/test/railties/railtie_test.rb
+16
-0
未找到文件。
railties/lib/rails/application.rb
浏览文件 @
f8e7904d
...
...
@@ -158,6 +158,14 @@ def load_console(app=self)
self
end
# Load the application runner and invoke the registered hooks.
# Check <tt>Rails::Railtie.runner</tt> for more info.
def
load_runner
(
app
=
self
)
initialize_runner
super
self
end
# Stores some of the Rails initial environment parameters which
# will be used by middlewares and engines to configure themselves.
def
env_config
...
...
@@ -304,6 +312,9 @@ def initialize_console #:nodoc:
require
"rails/console/helpers"
end
def
initialize_runner
#:nodoc:
end
def
build_original_fullpath
(
env
)
path_info
=
env
[
"PATH_INFO"
]
query_string
=
env
[
"QUERY_STRING"
]
...
...
railties/lib/rails/commands/runner.rb
浏览文件 @
f8e7904d
...
...
@@ -41,6 +41,7 @@
require
APP_PATH
Rails
.
application
.
require_environment!
Rails
.
application
.
load_runner
if
code_or_file
.
nil?
$stderr
.
puts
"Run '
#{
$0
}
-h' for help."
...
...
railties/lib/rails/engine.rb
浏览文件 @
f8e7904d
...
...
@@ -437,6 +437,11 @@ def load_console(app=self)
super
end
def
load_runner
(
app
=
self
)
railties
.
all
{
|
r
|
r
.
load_runner
(
app
)
}
super
end
def
eager_load!
railties
.
all
(
&
:eager_load!
)
...
...
railties/lib/rails/railtie.rb
浏览文件 @
f8e7904d
...
...
@@ -145,6 +145,12 @@ def console(&blk)
@load_console
end
def
runner
(
&
blk
)
@load_runner
||=
[]
@load_runner
<<
blk
if
blk
@load_runner
end
def
generators
(
&
blk
)
@generators
||=
[]
@generators
<<
blk
if
blk
...
...
@@ -179,6 +185,10 @@ def load_console(app=self)
self
.
class
.
console
.
each
{
|
block
|
block
.
call
(
app
)
}
end
def
load_runner
(
app
=
self
)
self
.
class
.
runner
.
each
{
|
block
|
block
.
call
(
app
)
}
end
def
load_tasks
(
app
=
self
)
extend
Rake
::
DSL
if
defined?
Rake
::
DSL
self
.
class
.
rake_tasks
.
each
{
|
block
|
self
.
instance_exec
(
app
,
&
block
)
}
...
...
railties/test/application/runner_test.rb
浏览文件 @
f8e7904d
...
...
@@ -57,5 +57,15 @@ def test_should_set_dollar_program_name_to_file
assert_match
"script/program_name.rb"
,
Dir
.
chdir
(
app_path
)
{
`bundle exec rails runner "script/program_name.rb"`
}
end
def
test_with_hook
add_to_config
<<-
RUBY
runner do |app|
app.config.ran = true
end
RUBY
assert_match
"true"
,
Dir
.
chdir
(
app_path
)
{
`bundle exec rails runner "puts Rails.application.config.ran"`
}
end
end
end
railties/test/railties/railtie_test.rb
浏览文件 @
f8e7904d
...
...
@@ -163,6 +163,22 @@ class MyTie < Rails::Railtie
assert
$ran_block
end
test
"runner block is executed when MyApp.load_runner is called"
do
$ran_block
=
false
class
MyTie
<
Rails
::
Railtie
runner
do
$ran_block
=
true
end
end
require
"
#{
app_path
}
/config/environment"
assert
!
$ran_block
AppTemplate
::
Application
.
load_runner
assert
$ran_block
end
test
"railtie can add initializers"
do
$ran_block
=
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录