Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
69c049f5
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,发现更多精彩内容 >>
提交
69c049f5
编写于
2月 20, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move development mode reloading up the stack to avoid issues with class reloading in middleware
上级
53fe301a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
52 addition
and
22 deletion
+52
-22
actionpack/lib/action_controller.rb
actionpack/lib/action_controller.rb
+1
-0
actionpack/lib/action_controller/dispatcher.rb
actionpack/lib/action_controller/dispatcher.rb
+27
-14
actionpack/lib/action_controller/reloader.rb
actionpack/lib/action_controller/reloader.rb
+14
-0
actionpack/test/controller/dispatcher_test.rb
actionpack/test/controller/dispatcher_test.rb
+8
-5
railties/lib/console_app.rb
railties/lib/console_app.rb
+1
-2
railties/lib/initializer.rb
railties/lib/initializer.rb
+1
-1
未找到文件。
actionpack/lib/action_controller.rb
浏览文件 @
69c049f5
...
...
@@ -59,6 +59,7 @@ def self.load_all!
autoload
:ParamsParser
,
'action_controller/params_parser'
autoload
:PolymorphicRoutes
,
'action_controller/polymorphic_routes'
autoload
:RecordIdentifier
,
'action_controller/record_identifier'
autoload
:Reloader
,
'action_controller/reloader'
autoload
:Request
,
'action_controller/request'
autoload
:RequestForgeryProtection
,
'action_controller/request_forgery_protection'
autoload
:Rescue
,
'action_controller/rescue'
...
...
actionpack/lib/action_controller/dispatcher.rb
浏览文件 @
69c049f5
...
...
@@ -5,8 +5,9 @@ class Dispatcher
class
<<
self
def
define_dispatcher_callbacks
(
cache_classes
)
unless
cache_classes
# Development mode callbacks
before_dispatch
:reload_application
unless
self
.
middleware
.
include?
(
Reloader
)
self
.
middleware
.
insert_after
(
Failsafe
,
Reloader
)
end
ActionView
::
Helpers
::
AssetTagHelper
.
cache_asset_timestamps
=
false
end
...
...
@@ -41,6 +42,30 @@ def to_prepare(identifier = nil, &block)
callback
=
ActiveSupport
::
Callbacks
::
Callback
.
new
(
:prepare_dispatch
,
block
,
:identifier
=>
identifier
)
@prepare_dispatch_callbacks
.
replace_or_append!
(
callback
)
end
def
run_prepare_callbacks
if
defined?
(
Rails
)
&&
Rails
.
logger
logger
=
Rails
.
logger
else
logger
=
Logger
.
new
(
$stderr
)
end
new
(
logger
).
send
:run_callbacks
,
:prepare_dispatch
end
def
reload_application
# Run prepare callbacks before every request in development mode
run_prepare_callbacks
Routing
::
Routes
.
reload
end
def
cleanup_application
# Cleanup the application before processing the current request.
ActiveRecord
::
Base
.
reset_subclasses
if
defined?
(
ActiveRecord
)
ActiveSupport
::
Dependencies
.
clear
ActiveRecord
::
Base
.
clear_reloadable_connections!
if
defined?
(
ActiveRecord
)
end
end
cattr_accessor
:middleware
...
...
@@ -87,18 +112,6 @@ def _call(env)
dispatch
end
def
reload_application
# Cleanup the application before processing the current request.
ActiveRecord
::
Base
.
reset_subclasses
if
defined?
(
ActiveRecord
)
ActiveSupport
::
Dependencies
.
clear
ActiveRecord
::
Base
.
clear_reloadable_connections!
if
defined?
(
ActiveRecord
)
# Run prepare callbacks before every request in development mode
run_callbacks
:prepare_dispatch
Routing
::
Routes
.
reload
end
def
flush_logger
Base
.
logger
.
flush
end
...
...
actionpack/lib/action_controller/reloader.rb
0 → 100644
浏览文件 @
69c049f5
module
ActionController
class
Reloader
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
Dispatcher
.
reload_application
@app
.
call
(
env
)
ensure
Dispatcher
.
cleanup_application
end
end
end
actionpack/test/controller/dispatcher_test.rb
浏览文件 @
69c049f5
...
...
@@ -6,14 +6,17 @@ class DispatcherTest < Test::Unit::TestCase
def
setup
ENV
[
'REQUEST_METHOD'
]
=
'GET'
Dispatcher
.
middleware
=
ActionController
::
MiddlewareStack
.
new
do
|
middleware
|
middlewares
=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"../../lib/action_controller/middlewares.rb"
))
middleware
.
instance_eval
(
File
.
read
(
middlewares
))
end
# Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
Dispatcher
.
instance_variable_set
(
"@prepare_dispatch_callbacks"
,
ActiveSupport
::
Callbacks
::
CallbackChain
.
new
)
Dispatcher
.
instance_variable_set
(
"@before_dispatch_callbacks"
,
ActiveSupport
::
Callbacks
::
CallbackChain
.
new
)
Dispatcher
.
instance_variable_set
(
"@after_dispatch_callbacks"
,
ActiveSupport
::
Callbacks
::
CallbackChain
.
new
)
Dispatcher
.
stubs
(
:require_dependency
)
@dispatcher
=
Dispatcher
.
new
end
def
teardown
...
...
@@ -65,7 +68,7 @@ def test_prepare_callbacks
assert_nil
a
||
b
||
c
# Run callbacks
@dispatcher
.
send
:run_callbacks
,
:prepare_dispatch
Dispatcher
.
run_prepare_callbacks
assert_equal
1
,
a
assert_equal
2
,
b
...
...
@@ -82,7 +85,7 @@ def test_to_prepare_with_identifier_replaces
Dispatcher
.
to_prepare
(
:unique_id
)
{
|*
args
|
a
=
b
=
1
}
Dispatcher
.
to_prepare
(
:unique_id
)
{
|*
args
|
a
=
2
}
@dispatcher
.
send
:run_callbacks
,
:prepare_dispatch
Dispatcher
.
run_prepare_callbacks
assert_equal
2
,
a
assert_equal
nil
,
b
end
...
...
@@ -91,7 +94,7 @@ def test_to_prepare_with_identifier_replaces
def
dispatch
(
cache_classes
=
true
)
ActionController
::
Routing
::
RouteSet
.
any_instance
.
stubs
(
:call
).
returns
([
200
,
{},
'response'
])
Dispatcher
.
define_dispatcher_callbacks
(
cache_classes
)
@dispatcher
.
call
({})
Dispatcher
.
new
.
call
({})
end
def
assert_subclasses
(
howmany
,
klass
,
message
=
klass
.
subclasses
.
inspect
)
...
...
railties/lib/console_app.rb
浏览文件 @
69c049f5
...
...
@@ -24,7 +24,6 @@ def new_session
#reloads the environment
def
reload!
puts
"Reloading..."
dispatcher
=
ActionController
::
Dispatcher
.
new
(
$stdout
)
dispatcher
.
reload_application
Dispatcher
.
reload_application
true
end
railties/lib/initializer.rb
浏览文件 @
69c049f5
...
...
@@ -583,7 +583,7 @@ def prepare_dispatcher
return
unless
configuration
.
frameworks
.
include?
(
:action_controller
)
require
'dispatcher'
unless
defined?
(
::
Dispatcher
)
Dispatcher
.
define_dispatcher_callbacks
(
configuration
.
cache_classes
)
Dispatcher
.
new
(
Rails
.
logger
).
send
:run_callbacks
,
:prepare_dispatch
Dispatcher
.
run_prepare_callbacks
end
def
disable_dependency_loading
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录