Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ad6be087
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,发现更多精彩内容 >>
提交
ad6be087
编写于
6月 22, 2010
作者:
P
Piotr Sarnacki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made Engine valid rack app with its own middleware stack
上级
f7af7597
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
65 addition
and
4 deletion
+65
-4
railties/lib/rails/application/configuration.rb
railties/lib/rails/application/configuration.rb
+1
-1
railties/lib/rails/application/railties.rb
railties/lib/rails/application/railties.rb
+2
-2
railties/lib/rails/engine.rb
railties/lib/rails/engine.rb
+13
-0
railties/lib/rails/engine/configurable.rb
railties/lib/rails/engine/configurable.rb
+12
-1
railties/lib/rails/engine/configuration.rb
railties/lib/rails/engine/configuration.rb
+2
-0
railties/test/railties/engine_test.rb
railties/test/railties/engine_test.rb
+35
-0
未找到文件。
railties/lib/rails/application/configuration.rb
浏览文件 @
ad6be087
...
...
@@ -9,7 +9,7 @@ class Configuration < ::Rails::Engine::Configuration
attr_accessor
:allow_concurrency
,
:cache_classes
,
:cache_store
,
:encoding
,
:consider_all_requests_local
,
:dependency_loading
,
:filter_parameters
,
:log_level
,
:logger
,
:middleware
,
:filter_parameters
,
:log_level
,
:logger
,
:plugins
,
:preload_frameworks
,
:reload_plugins
,
:secret_token
,
:serve_static_assets
,
:session_options
,
:time_zone
,
:whiny_nils
...
...
railties/lib/rails/application/railties.rb
浏览文件 @
ad6be087
...
...
@@ -17,7 +17,7 @@ def railties
end
def
engines
@engines
||=
::
Rails
::
Engine
.
subclasses
.
map
(
&
:
new
)
@engines
||=
::
Rails
::
Engine
.
subclasses
.
map
(
&
:
instance
)
end
def
plugins
...
...
@@ -28,4 +28,4 @@ def plugins
end
end
end
end
\ No newline at end of file
end
railties/lib/rails/engine.rb
浏览文件 @
ad6be087
...
...
@@ -140,6 +140,19 @@ def eager_load!
end
end
def
app
raise
"You can't use Engine as rack application without providing valid rack endpoint"
unless
endpoint
@app
||=
config
.
middleware
.
build
(
endpoint
)
end
def
endpoint
self
.
class
.
endpoint
end
def
call
(
env
)
app
.
call
(
env
)
end
# Add configured load paths to ruby load paths and remove duplicates.
initializer
:set_load_path
,
:before
=>
:bootstrap_hook
do
_all_load_paths
.
reverse_each
do
|
path
|
...
...
railties/lib/rails/engine/configurable.rb
浏览文件 @
ad6be087
...
...
@@ -3,10 +3,12 @@ class Engine
module
Configurable
def
self
.
included
(
base
)
base
.
extend
ClassMethods
base
.
private_class_method
:new
end
module
ClassMethods
delegate
:middleware
,
:root
,
:paths
,
:to
=>
:config
delegate
:call
,
:to
=>
:instance
def
config
@config
||=
Engine
::
Configuration
.
new
(
find_root_with_flag
(
"lib"
))
...
...
@@ -15,6 +17,15 @@ def config
def
inherited
(
base
)
raise
"You cannot inherit from a Rails::Engine child"
end
def
instance
@instance
||=
new
end
def
endpoint
(
endpoint
=
nil
)
@endpoint
=
endpoint
if
endpoint
@endpoint
end
end
def
config
...
...
@@ -22,4 +33,4 @@ def config
end
end
end
end
\ No newline at end of file
end
railties/lib/rails/engine/configuration.rb
浏览文件 @
ad6be087
...
...
@@ -5,10 +5,12 @@ class Engine
class
Configuration
<
::
Rails
::
Railtie
::
Configuration
attr_reader
:root
attr_writer
:eager_load_paths
,
:autoload_once_paths
,
:autoload_paths
attr_accessor
:middleware
def
initialize
(
root
=
nil
)
super
()
@root
=
root
@middleware
=
ActionDispatch
::
MiddlewareStack
.
new
end
def
paths
...
...
railties/test/railties/engine_test.rb
浏览文件 @
ad6be087
...
...
@@ -50,5 +50,40 @@ class Engine < ::Rails::Engine
assert
index
<
initializers
.
index
{
|
i
|
i
.
name
==
:build_middleware_stack
}
end
class
Upcaser
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
response
=
@app
.
call
(
env
)
response
[
2
].
upcase!
response
end
end
test
"engine is a rack app and can have his own middleware stack"
do
@plugin
.
write
"lib/bukkits.rb"
,
<<-
RUBY
class Bukkits
class Engine < ::Rails::Engine
endpoint lambda { |env| [200, {'Content-Type' => 'text/html'}, 'Hello World'] }
config.middleware.use ::RailtiesTest::EngineTest::Upcaser
end
end
RUBY
boot_rails
Rails
::
Application
.
routes
.
draw
do
|
map
|
mount
(
Bukkits
::
Engine
=>
"/bukkits"
)
end
env
=
Rack
::
MockRequest
.
env_for
(
"/bukkits"
)
response
=
Rails
::
Application
.
call
(
env
)
assert_equal
"HELLO WORLD"
,
response
[
2
]
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录