Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
530b8ff5
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,发现更多精彩内容 >>
提交
530b8ff5
编写于
11月 24, 2009
作者:
C
Carlhuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Have script/* and Rakefile use the application object
上级
a2cb90c0
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
61 addition
and
47 deletion
+61
-47
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+13
-5
railties/lib/rails/commands/console.rb
railties/lib/rails/commands/console.rb
+7
-3
railties/lib/rails/commands/dbconsole.rb
railties/lib/rails/commands/dbconsole.rb
+7
-3
railties/lib/rails/commands/server.rb
railties/lib/rails/commands/server.rb
+16
-3
railties/lib/rails/generators/rails/app/app_generator.rb
railties/lib/rails/generators/rails/app/app_generator.rb
+6
-2
railties/lib/rails/generators/rails/app/templates/Rakefile
railties/lib/rails/generators/rails/app/templates/Rakefile
+1
-1
railties/lib/rails/generators/rails/app/templates/config.ru
railties/lib/rails/generators/rails/app/templates/config.ru
+1
-1
railties/lib/rails/generators/rails/app/templates/config/application.rb
...ails/generators/rails/app/templates/config/application.rb
+1
-1
railties/lib/rails/generators/rails/app/templates/config/environment.rb
...ails/generators/rails/app/templates/config/environment.rb
+1
-1
railties/lib/rails/generators/rails/app/templates/script/console.tt
...ib/rails/generators/rails/app/templates/script/console.tt
+1
-1
railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
.../rails/generators/rails/app/templates/script/dbconsole.tt
+1
-1
railties/lib/rails/generators/rails/app/templates/script/server.tt
...lib/rails/generators/rails/app/templates/script/server.tt
+1
-1
railties/lib/rails/rack/log_tailer.rb
railties/lib/rails/rack/log_tailer.rb
+1
-3
railties/lib/rails/tasks/misc.rake
railties/lib/rails/tasks/misc.rake
+0
-4
railties/test/application/load_test.rb
railties/test/application/load_test.rb
+4
-17
未找到文件。
railties/lib/rails/application.rb
浏览文件 @
530b8ff5
...
...
@@ -3,11 +3,6 @@ class Application
include
Initializable
class
<<
self
def
inherited
(
klass
)
Rails
.
application
||=
klass
unless
klass
.
name
=~
/Rails/
super
end
# Stub out App initialize
def
initialize!
new
...
...
@@ -32,12 +27,21 @@ def root
config
.
root
end
def
load_tasks
require
"rails/tasks"
task
:environment
do
$rails_rake_task
=
true
initialize!
end
end
def
call
(
env
)
new
.
call
(
env
)
end
end
def
initialize
Rails
.
application
||=
self
run_initializers
(
self
)
end
...
...
@@ -45,6 +49,10 @@ def config
self
.
class
.
config
end
def
root
config
.
root
end
alias
configuration
config
def
middleware
...
...
railties/lib/rails/commands/console.rb
浏览文件 @
530b8ff5
...
...
@@ -6,8 +6,12 @@ module Rails
class
Console
ENVIRONMENTS
=
%w(production development test)
def
self
.
start
new
.
start
def
self
.
start
(
app
)
new
(
app
).
start
end
def
initialize
(
app
)
@app
=
app
end
def
start
...
...
@@ -25,7 +29,7 @@ def start
ENV
[
'RAILS_ENV'
]
=
ENVIRONMENTS
.
find
{
|
e
|
e
.
index
(
env
)
}
||
env
end
require
"
#{
Rails
.
root
}
/config/environment"
@app
.
initialize!
require
"rails/console_app"
require
"rails/console_sandbox"
if
options
[
:sandbox
]
require
"rails/console_with_helpers"
...
...
railties/lib/rails/commands/dbconsole.rb
浏览文件 @
530b8ff5
...
...
@@ -4,8 +4,12 @@
module
Rails
class
DBConsole
def
self
.
start
new
.
start
def
self
.
start
(
app
)
new
(
app
).
start
end
def
initialize
(
app
)
@app
=
app
end
def
start
...
...
@@ -31,7 +35,7 @@ def start
end
env
=
ARGV
.
first
||
ENV
[
'RAILS_ENV'
]
||
'development'
unless
config
=
YAML
::
load
(
ERB
.
new
(
IO
.
read
(
"
#{
Rails
.
root
}
/config/database.yml"
)).
result
)[
env
]
unless
config
=
YAML
::
load
(
ERB
.
new
(
IO
.
read
(
"
#{
@app
.
root
}
/config/database.yml"
)).
result
)[
env
]
abort
"No database is configured for the environment '
#{
env
}
'"
end
...
...
railties/lib/rails/commands/server.rb
浏览文件 @
530b8ff5
...
...
@@ -37,6 +37,15 @@ def opt_parser
Options
.
new
end
def
self
.
start
(
app
)
new
(
app
).
start
end
def
initialize
(
app
)
super
()
# Call Rack::Server#initialize without passing any options to use.
@app
=
app
end
def
start
puts
"=> Booting
#{
ActiveSupport
::
Inflector
.
demodulize
(
server
)
}
"
puts
"=> Rails
#{
Rails
.
version
}
application starting on http://
#{
options
[
:Host
]
}
:
#{
options
[
:Port
]
}
"
...
...
@@ -54,20 +63,24 @@ def start
def
middleware
middlewares
=
[]
middlewares
<<
[
Rails
::
Rack
::
LogTailer
]
unless
options
[
:daemonize
]
middlewares
<<
[
Rails
::
Rack
::
LogTailer
,
log_path
]
unless
options
[
:daemonize
]
middlewares
<<
[
Rails
::
Rack
::
Debugger
]
if
options
[
:debugger
]
Hash
.
new
(
middlewares
)
end
def
log_path
"
#{
File
.
expand_path
(
@app
.
root
)
}
/log/
#{
options
[
:environment
]
}
.log"
end
def
default_options
{
:Port
=>
3000
,
:Host
=>
"0.0.0.0"
,
:environment
=>
(
ENV
[
'RAILS_ENV'
]
||
"development"
).
dup
,
:rack_file
=>
"
#{
Rails
.
root
}
/config.ru"
,
:rack_file
=>
"
#{
@app
.
root
}
/config.ru"
,
:daemonize
=>
false
,
:debugger
=>
false
,
:pid
=>
"
#{
Rails
.
root
}
/tmp/pids/server.pid"
,
:pid
=>
"
#{
@app
.
root
}
/tmp/pids/server.pid"
,
:AccessLog
=>
[]
}
end
...
...
railties/lib/rails/generators/rails/app/app_generator.rb
浏览文件 @
530b8ff5
...
...
@@ -48,9 +48,9 @@ def create_root
end
def
create_root_files
copy_file
"Rakefile"
copy_file
"README"
copy_file
"config.ru"
template
"Rakefile"
template
"config.ru"
template
"Gemfile"
end
...
...
@@ -181,6 +181,10 @@ def app_name
@app_name
||=
File
.
basename
(
destination_root
)
end
def
app_const
@app_const
||=
app_name
.
classify
end
def
app_secret
ActiveSupport
::
SecureRandom
.
hex
(
64
)
end
...
...
railties/lib/rails/generators/rails/app/templates/Rakefile
浏览文件 @
530b8ff5
...
...
@@ -7,4 +7,4 @@ require 'rake'
require
'rake/testtask'
require
'rake/rdoctask'
require
'rails/tasks'
<
%= app_const %>.load_tasks
railties/lib/rails/generators/rails/app/templates/config.ru
浏览文件 @
530b8ff5
...
...
@@ -2,4 +2,4 @@
require
::
File
.
expand_path
(
'../config/environment'
,
__FILE__
)
# Dispatch the request
run
Rails
.
application
run
<
%= app_const%>
railties/lib/rails/generators/rails/app/templates/config/application.rb
浏览文件 @
530b8ff5
require
File
.
expand_path
(
'../boot'
,
__FILE__
)
Rails
::
Initializer
.
run
do
|
config
|
class
<
%= app_const %> < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
...
...
railties/lib/rails/generators/rails/app/templates/config/environment.rb
浏览文件 @
530b8ff5
...
...
@@ -2,4 +2,4 @@
require
File
.
expand_path
(
'../application'
,
__FILE__
)
# Initialize the rails application
Rails
.
initialize!
<
%= app_const %>
.initialize!
railties/lib/rails/generators/rails/app/templates/script/console
→
railties/lib/rails/generators/rails/app/templates/script/console
.tt
浏览文件 @
530b8ff5
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/console'
Rails::Console.start
Rails::Console.start
(<%= app_const %>)
railties/lib/rails/generators/rails/app/templates/script/dbconsole
→
railties/lib/rails/generators/rails/app/templates/script/dbconsole
.tt
浏览文件 @
530b8ff5
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/dbconsole'
Rails::DBConsole.start
\ No newline at end of file
Rails::DBConsole.start(<%= app_const %>)
\ No newline at end of file
railties/lib/rails/generators/rails/app/templates/script/server
→
railties/lib/rails/generators/rails/app/templates/script/server
.tt
浏览文件 @
530b8ff5
require File.expand_path('../../config/application', __FILE__)
require 'rails/commands/server'
Rails::Server.start
Rails::Server.start
(<%= app_const %>)
railties/lib/rails/rack/log_tailer.rb
浏览文件 @
530b8ff5
module
Rails
module
Rack
class
LogTailer
EnvironmentLog
=
"
#{
File
.
expand_path
(
Rails
.
root
)
}
/log/
#{
Rails
.
env
}
.log"
def
initialize
(
app
,
log
=
nil
)
@app
=
app
path
=
Pathname
.
new
(
log
||
EnvironmentLog
).
cleanpath
path
=
Pathname
.
new
(
log
||
"
#{
File
.
expand_path
(
Rails
.
root
)
}
/log/
#{
Rails
.
env
}
.log"
).
cleanpath
@cursor
=
::
File
.
size
(
path
)
@last_checked
=
Time
.
now
.
to_f
...
...
railties/lib/rails/tasks/misc.rake
浏览文件 @
530b8ff5
task
:default
=>
:test
task
:environment
do
$rails_rake_task
=
true
require
(
File
.
join
(
Rails
.
root
,
'config'
,
'environment'
))
end
task
:rails_env
do
unless
defined?
RAILS_ENV
...
...
railties/test/application/load_test.rb
浏览文件 @
530b8ff5
...
...
@@ -7,21 +7,8 @@ class LoadTest < Test::Unit::TestCase
include
ActiveSupport
::
Testing
::
Isolation
def
rackup
config
=
"
#{
app_path
}
/config.ru"
# Copied from ActionDispatch::Utils.parse_config
# ActionDispatch is not necessarily available at this point.
require
'rack'
if
config
=~
/\.ru$/
cfgfile
=
::
File
.
read
(
config
)
if
cfgfile
[
/^#\\(.*)/
]
opts
.
parse!
$1
.
split
(
/\s+/
)
end
inner_app
=
eval
"Rack::Builder.new {( "
+
cfgfile
+
"
\n
)}.to_app"
,
nil
,
config
else
require
config
inner_app
=
Object
.
const_get
(
::
File
.
basename
(
config
,
'.rb'
).
capitalize
)
end
require
"rack"
Rack
::
Builder
.
parse_file
(
"
#{
app_path
}
/config.ru"
)
end
def
setup
...
...
@@ -40,14 +27,14 @@ def setup
test
"Rails.application is available after config.ru has been racked up"
do
rackup
assert
Rails
.
application
<
Rails
::
Application
assert
Rails
.
application
.
is_a?
(
Rails
::
Application
)
end
# Passenger still uses AC::Dispatcher, so we need to
# keep it working for now
test
"deprecated ActionController::Dispatcher still works"
do
rackup
assert
ActionController
::
Dispatcher
.
new
<
Rails
::
Application
assert
ActionController
::
Dispatcher
.
new
.
is_a?
(
Rails
::
Application
)
end
test
"the config object is available on the application object"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录