класс Rails::Command::Base
Публичные методы класса
# File railties/lib/rails/command/base.rb, line 86
def banner(command = nil, *)
if command
# Similar to Thor's banner, but show the namespace (minus the
# "rails:" prefix), and show the command's declared bin instead of
# the command runner.
command.formatted_usage(self).gsub(/^#{namespace}:(\w+)/) { executable($1) }
else
executable
end
end # 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 Устанавливает base_name с учетом текущего пространства имен класса.
Rails::Command::TestCommand.base_name # => 'rails'
# 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 Возвращает имя команды без пространств имен.
Rails::Command::TestCommand.command_name # => 'test'
# 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 Корень файла по умолчанию для размещения дополнительных файлов, необходимых команде, расположенный на один каталог выше файла команды.
Для Rails::Command::TestCommand, расположенного в rails/command/test_command.rb вернет rails/test.
# File railties/lib/rails/command/base.rb, line 34
def desc(usage = nil, description = nil, options = {})
if usage
super
else
class_usage
end
end Попытка получить описание из файла USAGE, расположенного на один каталог выше корня команды.
# File railties/lib/rails/command/base.rb, line 28 def engine? defined?(ENGINE_ROOT) end
Возвращает true, если приложение является Rails-плагином.
# File railties/lib/rails/command/base.rb, line 82
def executable(command_name = self.command_name)
"#{bin} #{namespaced_name(command_name)}"
end # File railties/lib/rails/command/base.rb, line 55 def hide_command! Rails::Command.hidden_commands << self end
Удобный метод для скрытия этой команды из доступных при запуске rails command.
# 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 Удобный метод для получения пространства имен из имени класса. Он такой же, как по умолчанию в Thor, за исключением того, что Command в конце класса удаляется.
# 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 # File railties/lib/rails/command/base.rb, line 129
def usage_path
@usage_path = resolve_path("USAGE") unless defined?(@usage_path)
@usage_path
end Путь для поиска описания USAGE в файле.
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.