- B
- C
- D
- E
- H
- N
- P
- U
类公共方法
base_name() 链接
设置 base_name
,同时考虑当前类的命名空间。
Rails::Command::TestCommand.base_name # => 'rails'
源代码: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 106 def base_name @base_name ||= if base = name.to_s.split("::").first base.underscore end end
command_name() 链接
返回不带命名空间的命令名称。
Rails::Command::TestCommand.command_name # => 'test'
源代码: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 115 def command_name @command_name ||= if command = name.to_s.split("::").last command.chomp!("Command") command.underscore end end
default_command_root() 链接
默认文件根目录,用于放置命令可能需要的额外文件,位于命令文件的上一个文件夹。
对于放置在 rails/command/test_command.rb
中的 Rails::Command::TestCommand,将返回 rails/test
。
源代码: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 139 def default_command_root @default_command_root = resolve_path(".") unless defined?(@default_command_root) @default_command_root end
desc(usage = nil, description = nil, options = {}) 链接
尝试从命令根目录上一个文件夹的 USAGE 文件中获取描述。
来源: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 34 def desc(usage = nil, description = nil, options = {}) if usage super else class_usage end end
engine?() 链接
当应用程序是 Rails 引擎时返回 true。
来源: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 28 def engine? defined?(ENGINE_ROOT) end
executable(command_name = self.command_name) 链接
来源: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 82 def executable(command_name = self.command_name) "#{bin} #{namespaced_name(command_name)}" end
hide_command!() 链接
方便方法,用于在运行 rails 命令时从可用命令中隐藏此命令。
来源: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 55 def hide_command! Rails::Command.hidden_commands << self end
namespace(name = nil) 链接
方便方法,用于从类名获取命名空间。它与 Thor 默认值相同,只是类末尾的 Command
被删除了。
来源: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 45 def namespace(name = nil) if name super else @namespace ||= super.chomp("_command").sub(/:command:/, ":") end end
printing_commands() 链接
来源: 显示 | 在 GitHub 上
# File railties/lib/rails/command/base.rb, line 76 def printing_commands commands.filter_map do |name, command| [namespaced_name(name), command.description] unless command.hidden? end end
usage_path() 链接
在文件中查找 USAGE 描述的路径。
来源:显示 | 在 GitHub 上查看
# File railties/lib/rails/command/base.rb, line 129 def usage_path @usage_path = resolve_path("USAGE") unless defined?(@usage_path) @usage_path end