Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2d00aa7a
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,发现更多精彩内容 >>
提交
2d00aa7a
编写于
8月 05, 2015
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20961 from ccallebs/add-dev-mode-caching
Add dev caching toggle / server options
上级
57989c58
a01e58af
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
114 addition
and
2 deletion
+114
-2
railties/CHANGELOG.md
railties/CHANGELOG.md
+12
-0
railties/lib/rails/commands/server.rb
railties/lib/rails/commands/server.rb
+23
-0
railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
...rails/app/templates/config/environments/development.rb.tt
+12
-2
railties/lib/rails/tasks.rb
railties/lib/rails/tasks.rb
+1
-0
railties/lib/rails/tasks/dev.rake
railties/lib/rails/tasks/dev.rake
+15
-0
railties/test/application/rake/dev_test.rb
railties/test/application/rake/dev_test.rb
+35
-0
railties/test/commands/server_test.rb
railties/test/commands/server_test.rb
+16
-0
未找到文件。
railties/CHANGELOG.md
浏览文件 @
2d00aa7a
*
Make enabling or disabling caching in development mode possible with
rake dev:cache.
Running rake dev:cache will create or remove tmp/caching-dev.txt. When this
file exists config.action_controller.perform_caching will be set to true in
config/environments/development.rb.
Additionally, a server can be started with either --dev-caching or
--no-dev-caching included to toggle caching on startup.
*Jussi Mertanen*, *Chuck Callebs*
*
Add a
`--api`
option in order to generate plugins that can be added
inside an API application.
...
...
railties/lib/rails/commands/server.rb
浏览文件 @
2d00aa7a
...
...
@@ -34,6 +34,9 @@ def option_parser(options)
opts
.
on
(
"-P"
,
"--pid=pid"
,
String
,
"Specifies the PID file."
,
"Default: tmp/pids/server.pid"
)
{
|
v
|
options
[
:pid
]
=
v
}
opts
.
on
(
"-C"
,
"--[no-]dev-caching"
,
"Specifies whether to perform caching in development."
,
"true or false"
)
{
|
v
|
options
[
:caching
]
=
v
}
opts
.
separator
""
...
...
@@ -67,6 +70,7 @@ def start
print_boot_information
trap
(
:INT
)
{
exit
}
create_tmp_directories
setup_dev_caching
log_to_stdout
if
options
[
:log_stdout
]
super
...
...
@@ -86,12 +90,23 @@ def default_options
DoNotReverseLookup
:
true
,
environment:
(
ENV
[
'RAILS_ENV'
]
||
ENV
[
'RACK_ENV'
]
||
"development"
).
dup
,
daemonize:
false
,
caching:
false
,
pid:
File
.
expand_path
(
"tmp/pids/server.pid"
)
})
end
private
def
setup_dev_caching
return
unless
options
[
:environment
]
==
"development"
if
options
[
:caching
]
==
false
delete_cache_file
elsif
options
[
:caching
]
create_cache_file
end
end
def
print_boot_information
url
=
"
#{
options
[
:SSLEnable
]
?
'https'
:
'http'
}
://
#{
options
[
:Host
]
}
:
#{
options
[
:Port
]
}
"
puts
"=> Booting
#{
ActiveSupport
::
Inflector
.
demodulize
(
server
)
}
"
...
...
@@ -101,6 +116,14 @@ def print_boot_information
puts
"=> Ctrl-C to shutdown server"
unless
options
[
:daemonize
]
end
def
create_cache_file
FileUtils
.
touch
(
"tmp/caching-dev.txt"
)
end
def
delete_cache_file
FileUtils
.
rm
(
"tmp/caching-dev.txt"
)
if
File
.
exists?
(
"tmp/caching-dev.txt"
)
end
def
create_tmp_directories
%w(cache pids sockets)
.
each
do
|
dir_to_make
|
FileUtils
.
mkdir_p
(
File
.
join
(
Rails
.
root
,
'tmp'
,
dir_to_make
))
...
...
railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
浏览文件 @
2d00aa7a
...
...
@@ -9,9 +9,19 @@ Rails.application.configure do
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports
and disable caching
.
# Show full error reports.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.static_cache_control = "public, max-age=172800"
config.cache_store = :memory_store
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
<%- unless options.skip_action_mailer? -%>
# Don't care if the mailer can't send.
...
...
railties/lib/rails/tasks.rb
浏览文件 @
2d00aa7a
...
...
@@ -3,6 +3,7 @@
# Load Rails Rakefile extensions
%w(
annotations
dev
framework
initializers
log
...
...
railties/lib/rails/tasks/dev.rake
0 → 100644
浏览文件 @
2d00aa7a
namespace
:dev
do
task
:cache
do
desc
'Toggle development mode caching on/off'
if
File
.
exist?
'tmp/caching-dev.txt'
File
.
delete
'tmp/caching-dev.txt'
puts
'Development mode is no longer being cached.'
else
FileUtils
.
touch
'tmp/caching-dev.txt'
puts
'Development mode is now being cached.'
end
FileUtils
.
touch
'tmp/restart.txt'
end
end
railties/test/application/rake/dev_test.rb
0 → 100644
浏览文件 @
2d00aa7a
require
'isolation/abstract_unit'
module
ApplicationTests
module
RakeTests
class
RakeDevTest
<
ActiveSupport
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
def
setup
build_app
boot_rails
end
def
teardown
teardown_app
end
test
'dev:cache creates file and outputs message'
do
Dir
.
chdir
(
app_path
)
do
output
=
`rake dev:cache`
assert
File
.
exist?
(
'tmp/caching-dev.txt'
)
assert_match
(
/Development mode is now being cached/
,
output
)
end
end
test
'dev:cache deletes file and outputs message'
do
Dir
.
chdir
(
app_path
)
do
output
=
`rake dev:cache`
output
=
`rake dev:cache`
assert_not
File
.
exist?
(
'tmp/caching-dev.txt'
)
assert_match
(
/Development mode is no longer being cached/
,
output
)
end
end
end
end
end
railties/test/commands/server_test.rb
浏览文件 @
2d00aa7a
...
...
@@ -44,6 +44,22 @@ def test_environment_with_rack_env
end
end
def
test_caching_without_option
args
=
[]
options
=
Rails
::
Server
::
Options
.
new
.
parse!
(
args
)
assert_equal
nil
,
options
[
:caching
]
end
def
test_caching_with_option
args
=
[
"--dev-caching"
]
options
=
Rails
::
Server
::
Options
.
new
.
parse!
(
args
)
assert_equal
true
,
options
[
:caching
]
args
=
[
"--no-dev-caching"
]
options
=
Rails
::
Server
::
Options
.
new
.
parse!
(
args
)
assert_equal
false
,
options
[
:caching
]
end
def
test_log_stdout
with_rack_env
nil
do
with_rails_env
nil
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录