Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1cdc6c65
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,发现更多精彩内容 >>
未验证
提交
1cdc6c65
编写于
3月 15, 2019
作者:
Y
Yuji Yaginuma
提交者:
GitHub
3月 15, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #35599 from y-yagi/improve_environment_argument_handling
Properly expand the environment's name in all commands
上级
85984e50
c801b232
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
48 addition
and
12 deletion
+48
-12
railties/lib/rails/command/environment_argument.rb
railties/lib/rails/command/environment_argument.rb
+5
-4
railties/lib/rails/commands/credentials/credentials_command.rb
...ies/lib/rails/commands/credentials/credentials_command.rb
+5
-2
railties/lib/rails/commands/runner/runner_command.rb
railties/lib/rails/commands/runner/runner_command.rb
+7
-3
railties/lib/rails/commands/server/server_command.rb
railties/lib/rails/commands/server/server_command.rb
+4
-2
railties/test/application/runner_test.rb
railties/test/application/runner_test.rb
+4
-0
railties/test/commands/credentials_test.rb
railties/test/commands/credentials_test.rb
+14
-0
railties/test/commands/server_test.rb
railties/test/commands/server_test.rb
+9
-1
未找到文件。
railties/lib/rails/command/environment_argument.rb
浏览文件 @
1cdc6c65
# frozen_string_literal: true
# frozen_string_literal: true
require
"active_support"
require
"active_support"
require
"active_support/core_ext/class/attribute"
module
Rails
module
Rails
module
Command
module
Command
...
@@ -8,16 +9,16 @@ module EnvironmentArgument #:nodoc:
...
@@ -8,16 +9,16 @@ module EnvironmentArgument #:nodoc:
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
class_
option
:environment
,
aliases:
"-e"
,
type: :string
,
class_
attribute
:environment_desc
,
default:
"Specifies the environment to run this
#{
self
.
command_name
}
under (test/development/production)."
desc:
"Specifies the environment to run this console under (test/development/production)."
class_option
:environment
,
aliases:
"-e"
,
type: :string
,
desc:
environment_desc
end
end
private
private
def
extract_environment_option_from_argument
def
extract_environment_option_from_argument
(
default_environment:
Rails
::
Command
.
environment
)
if
options
[
:environment
]
if
options
[
:environment
]
self
.
options
=
options
.
merge
(
environment:
acceptable_environment
(
options
[
:environment
]))
self
.
options
=
options
.
merge
(
environment:
acceptable_environment
(
options
[
:environment
]))
else
else
self
.
options
=
options
.
merge
(
environment:
Rails
::
Command
.
environment
)
self
.
options
=
options
.
merge
(
environment:
default_
environment
)
end
end
end
end
...
...
railties/lib/rails/commands/credentials/credentials_command.rb
浏览文件 @
1cdc6c65
...
@@ -2,14 +2,15 @@
...
@@ -2,14 +2,15 @@
require
"active_support"
require
"active_support"
require
"rails/command/helpers/editor"
require
"rails/command/helpers/editor"
require
"rails/command/environment_argument"
module
Rails
module
Rails
module
Command
module
Command
class
CredentialsCommand
<
Rails
::
Command
::
Base
# :nodoc:
class
CredentialsCommand
<
Rails
::
Command
::
Base
# :nodoc:
include
Helpers
::
Editor
include
Helpers
::
Editor
include
EnvironmentArgument
class_option
:environment
,
aliases:
"-e"
,
type: :string
,
self
.
environment_desc
=
"Uses credentials from config/credentials/:environment.yml.enc encrypted by config/credentials/:environment.key key"
desc:
"Uses credentials from config/credentials/:environment.yml.enc encrypted by config/credentials/:environment.key key"
no_commands
do
no_commands
do
def
help
def
help
...
@@ -20,6 +21,7 @@ def help
...
@@ -20,6 +21,7 @@ def help
end
end
def
edit
def
edit
extract_environment_option_from_argument
(
default_environment:
nil
)
require_application!
require_application!
ensure_editor_available
(
command:
"bin/rails credentials:edit"
)
||
(
return
)
ensure_editor_available
(
command:
"bin/rails credentials:edit"
)
||
(
return
)
...
@@ -37,6 +39,7 @@ def edit
...
@@ -37,6 +39,7 @@ def edit
end
end
def
show
def
show
extract_environment_option_from_argument
(
default_environment:
nil
)
require_application!
require_application!
say
credentials
.
read
.
presence
||
missing_credentials_message
say
credentials
.
read
.
presence
||
missing_credentials_message
...
...
railties/lib/rails/commands/runner/runner_command.rb
浏览文件 @
1cdc6c65
# frozen_string_literal: true
# frozen_string_literal: true
require
"rails/command/environment_argument"
module
Rails
module
Rails
module
Command
module
Command
class
RunnerCommand
<
Base
# :nodoc:
class
RunnerCommand
<
Base
# :nodoc:
class_option
:environment
,
aliases:
"-e"
,
type: :string
,
include
EnvironmentArgument
default:
Rails
::
Command
.
environment
.
dup
,
desc:
"The environment for the runner to operate under (test/development/production)"
self
.
environment_desc
=
"The environment for the runner to operate under (test/development/production)"
no_commands
do
no_commands
do
def
help
def
help
...
@@ -19,6 +21,8 @@ def self.banner(*)
...
@@ -19,6 +21,8 @@ def self.banner(*)
end
end
def
perform
(
code_or_file
=
nil
,
*
command_argv
)
def
perform
(
code_or_file
=
nil
,
*
command_argv
)
extract_environment_option_from_argument
unless
code_or_file
unless
code_or_file
help
help
exit
1
exit
1
...
...
railties/lib/rails/commands/server/server_command.rb
浏览文件 @
1cdc6c65
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
require
"active_support/deprecation"
require
"active_support/deprecation"
require
"active_support/core_ext/string/filters"
require
"active_support/core_ext/string/filters"
require
"rails/dev_caching"
require
"rails/dev_caching"
require
"rails/command/environment_argument"
module
Rails
module
Rails
class
Server
<
::
Rack
::
Server
class
Server
<
::
Rack
::
Server
...
@@ -91,6 +92,8 @@ def use_puma?
...
@@ -91,6 +92,8 @@ def use_puma?
module
Command
module
Command
class
ServerCommand
<
Base
# :nodoc:
class
ServerCommand
<
Base
# :nodoc:
include
EnvironmentArgument
# Hard-coding a bunch of handlers here as we don't have a public way of
# Hard-coding a bunch of handlers here as we don't have a public way of
# querying them from the Rack::Handler registry.
# querying them from the Rack::Handler registry.
RACK_SERVERS
=
%w(cgi fastcgi webrick lsws scgi thin puma unicorn)
RACK_SERVERS
=
%w(cgi fastcgi webrick lsws scgi thin puma unicorn)
...
@@ -109,8 +112,6 @@ class ServerCommand < Base # :nodoc:
...
@@ -109,8 +112,6 @@ class ServerCommand < Base # :nodoc:
desc:
"Uses a custom rackup configuration."
,
banner: :file
desc:
"Uses a custom rackup configuration."
,
banner: :file
class_option
:daemon
,
aliases:
"-d"
,
type: :boolean
,
default:
false
,
class_option
:daemon
,
aliases:
"-d"
,
type: :boolean
,
default:
false
,
desc:
"Runs server as a Daemon."
desc:
"Runs server as a Daemon."
class_option
:environment
,
aliases:
"-e"
,
type: :string
,
desc:
"Specifies the environment to run this server under (development/test/production)."
,
banner: :name
class_option
:using
,
aliases:
"-u"
,
type: :string
,
class_option
:using
,
aliases:
"-u"
,
type: :string
,
desc:
"Specifies the Rack server used to run the application (thin/puma/webrick)."
,
banner: :name
desc:
"Specifies the Rack server used to run the application (thin/puma/webrick)."
,
banner: :name
class_option
:pid
,
aliases:
"-P"
,
type: :string
,
default:
DEFAULT_PID_PATH
,
class_option
:pid
,
aliases:
"-P"
,
type: :string
,
default:
DEFAULT_PID_PATH
,
...
@@ -130,6 +131,7 @@ def initialize(args, local_options, *)
...
@@ -130,6 +131,7 @@ def initialize(args, local_options, *)
end
end
def
perform
def
perform
extract_environment_option_from_argument
set_application_directory!
set_application_directory!
prepare_restart
prepare_restart
...
...
railties/test/application/runner_test.rb
浏览文件 @
1cdc6c65
...
@@ -109,6 +109,10 @@ def test_environment_option
...
@@ -109,6 +109,10 @@ def test_environment_option
assert_match
"production"
,
rails
(
"runner"
,
"-e"
,
"production"
,
"puts Rails.env"
)
assert_match
"production"
,
rails
(
"runner"
,
"-e"
,
"production"
,
"puts Rails.env"
)
end
end
def
test_environment_option_is_properly_expanded
assert_match
"production"
,
rails
(
"runner"
,
"-e"
,
"prod"
,
"puts Rails.env"
)
end
def
test_runner_detects_syntax_errors
def
test_runner_detects_syntax_errors
output
=
rails
(
"runner"
,
"puts 'hello world"
,
allow_failure:
true
)
output
=
rails
(
"runner"
,
"puts 'hello world"
,
allow_failure:
true
)
assert_not_predicate
$?
,
:success?
assert_not_predicate
$?
,
:success?
...
...
railties/test/commands/credentials_test.rb
浏览文件 @
1cdc6c65
...
@@ -63,6 +63,14 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
...
@@ -63,6 +63,14 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
end
end
end
end
test
"edit command properly expand environment option"
do
assert_match
(
/access_key_id: 123/
,
run_edit_command
(
environment:
"prod"
))
Dir
.
chdir
(
app_path
)
do
assert
File
.
exist?
(
"config/credentials/production.key"
)
assert
File
.
exist?
(
"config/credentials/production.yml.enc"
)
end
end
test
"edit command does not raise when an initializer tries to access non-existent credentials"
do
test
"edit command does not raise when an initializer tries to access non-existent credentials"
do
app_file
"config/initializers/raise_when_loaded.rb"
,
<<-
RUBY
app_file
"config/initializers/raise_when_loaded.rb"
,
<<-
RUBY
Rails.application.credentials.missing_key!
Rails.application.credentials.missing_key!
...
@@ -95,6 +103,12 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
...
@@ -95,6 +103,12 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
assert_match
(
/access_key_id: 123/
,
run_show_command
(
environment:
"production"
))
assert_match
(
/access_key_id: 123/
,
run_show_command
(
environment:
"production"
))
end
end
test
"show command properly expand environment option"
do
run_edit_command
(
environment:
"production"
)
assert_match
(
/access_key_id: 123/
,
run_show_command
(
environment:
"prod"
))
end
private
private
def
run_edit_command
(
editor:
"cat"
,
environment:
nil
,
**
options
)
def
run_edit_command
(
editor:
"cat"
,
environment:
nil
,
**
options
)
switch_env
(
"EDITOR"
,
editor
)
do
switch_env
(
"EDITOR"
,
editor
)
do
...
...
railties/test/commands/server_test.rb
浏览文件 @
1cdc6c65
...
@@ -22,6 +22,12 @@ def test_environment_without_server_option
...
@@ -22,6 +22,12 @@ def test_environment_without_server_option
assert_nil
options
[
:server
]
assert_nil
options
[
:server
]
end
end
def
test_environment_option_is_properly_expanded
args
=
[
"-e"
,
"prod"
]
options
=
parse_arguments
(
args
)
assert_equal
"production"
,
options
[
:environment
]
end
def
test_explicit_using_option
def
test_explicit_using_option
args
=
[
"-u"
,
"thin"
]
args
=
[
"-u"
,
"thin"
]
options
=
parse_arguments
(
args
)
options
=
parse_arguments
(
args
)
...
@@ -285,6 +291,8 @@ def run_command(*args)
...
@@ -285,6 +291,8 @@ def run_command(*args)
end
end
def
parse_arguments
(
args
=
[])
def
parse_arguments
(
args
=
[])
Rails
::
Command
::
ServerCommand
.
new
([],
args
).
server_options
command
=
Rails
::
Command
::
ServerCommand
.
new
([],
args
)
command
.
send
(
:extract_environment_option_from_argument
)
command
.
server_options
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录