Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
918dc273
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,发现更多精彩内容 >>
提交
918dc273
编写于
9月 27, 2010
作者:
T
thedarkone
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Compile ActionController::Base.config's methods to avoid method_missing overhead.
上级
7918a5c9
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
55 addition
and
4 deletion
+55
-4
actionpack/lib/action_controller/railtie.rb
actionpack/lib/action_controller/railtie.rb
+10
-0
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+1
-2
activesupport/lib/active_support/configurable.rb
activesupport/lib/active_support/configurable.rb
+22
-2
activesupport/lib/active_support/ordered_options.rb
activesupport/lib/active_support/ordered_options.rb
+4
-0
activesupport/test/configurable_test.rb
activesupport/test/configurable_test.rb
+18
-0
未找到文件。
actionpack/lib/action_controller/railtie.rb
浏览文件 @
918dc273
...
...
@@ -26,6 +26,10 @@ class Railtie < Rails::Railtie
options
.
stylesheets_dir
||=
paths
.
public
.
stylesheets
.
to_a
.
first
options
.
page_cache_directory
||=
paths
.
public
.
to_a
.
first
# make sure readers methods get compiled
options
.
asset_path
||=
nil
options
.
asset_host
||=
nil
ActiveSupport
.
on_load
(
:action_controller
)
do
include
app
.
routes
.
mounted_helpers
extend
::
AbstractController
::
Railties
::
RoutesHelpers
.
with
(
app
.
routes
)
...
...
@@ -33,5 +37,11 @@ class Railtie < Rails::Railtie
options
.
each
{
|
k
,
v
|
send
(
"
#{
k
}
="
,
v
)
}
end
end
config
.
after_initialize
do
ActiveSupport
.
on_load
(
:action_controller
)
do
config
.
crystalize!
if
config
.
respond_to?
(
:crystalize!
)
end
end
end
end
actionpack/lib/action_view/base.rb
浏览文件 @
918dc273
...
...
@@ -209,8 +209,7 @@ def initialize(lookup_context = nil, assigns_for_first_render = {}, controller =
@_request
=
controller
.
request
if
controller
.
respond_to?
(
:request
)
end
config
=
controller
&&
controller
.
respond_to?
(
:config
)
?
controller
.
config
:
{}
@_config
=
ActiveSupport
::
InheritableOptions
.
new
(
config
)
@_config
=
controller
&&
controller
.
respond_to?
(
:config
)
?
controller
.
config
.
inheritable_copy
:
{}
@_content_for
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
ActiveSupport
::
SafeBuffer
.
new
}
@_virtual_path
=
nil
...
...
activesupport/lib/active_support/configurable.rb
浏览文件 @
918dc273
...
...
@@ -9,9 +9,29 @@ module ActiveSupport
module
Configurable
extend
ActiveSupport
::
Concern
class
Configuration
<
ActiveSupport
::
InheritableOptions
def
crystalize!
self
.
class
.
crystalize!
(
keys
.
reject
{
|
key
|
respond_to?
(
key
)})
end
# compiles reader methods so we don't have to go through method_missing
def
self
.
crystalize!
(
keys
)
keys
.
each
do
|
key
|
class_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def
#{
key
}
; self[
#{
key
.
inspect
}
]; end
RUBY
end
end
end
module
ClassMethods
def
config
@_config
||=
ActiveSupport
::
InheritableOptions
.
new
(
superclass
.
respond_to?
(
:config
)
?
superclass
.
config
:
{})
@_config
||=
if
superclass
.
respond_to?
(
:config
)
superclass
.
config
.
inheritable_copy
else
# create a new "anonymous" class that will host the compiled reader methods
Class
.
new
(
Configuration
).
new
({})
end
end
def
configure
...
...
@@ -48,7 +68,7 @@ def #{name}=(value); config.#{name} = value; end
# user.config.level # => 1
#
def
config
@_config
||=
ActiveSupport
::
InheritableOptions
.
new
(
self
.
class
.
config
)
@_config
||=
self
.
class
.
config
.
inheritable_copy
end
end
end
...
...
activesupport/lib/active_support/ordered_options.rb
浏览文件 @
918dc273
...
...
@@ -39,5 +39,9 @@ class InheritableOptions < OrderedOptions
def
initialize
(
parent
)
super
()
{
|
h
,
k
|
parent
[
k
]
}
end
def
inheritable_copy
self
.
class
.
new
(
self
)
end
end
end
activesupport/test/configurable_test.rb
浏览文件 @
918dc273
...
...
@@ -39,4 +39,22 @@ class Child < Parent
assert_equal
:baz
,
instance
.
config
.
foo
assert_equal
:bar
,
Parent
.
config
.
foo
end
test
"configuration is crystalizeable"
do
parent
=
Class
.
new
{
include
ActiveSupport
::
Configurable
}
child
=
Class
.
new
(
parent
)
parent
.
config
.
bar
=
:foo
assert
!
parent
.
config
.
respond_to?
(
:bar
)
assert
!
child
.
config
.
respond_to?
(
:bar
)
assert
!
child
.
new
.
config
.
respond_to?
(
:bar
)
parent
.
config
.
crystalize!
assert_equal
:foo
,
parent
.
config
.
bar
assert_equal
:foo
,
child
.
new
.
config
.
bar
assert_respond_to
parent
.
config
,
:bar
assert_respond_to
child
.
config
,
:bar
assert_respond_to
child
.
new
.
config
,
:bar
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录