Spec-Zone.ru › Ruby on Rails 8.1

класс Rails::Command::Base

Подключенные модули:
Rails::Command::Actions

Публичные методы класса

banner (command = nil, *) Показать исходный код
# File railties/lib/rails/command/base.rb, line 84
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
base_name () Показать исходный код
# File railties/lib/rails/command/base.rb, line 104
def base_name
  @base_name ||= if base = name.to_s.split("::").first
    base.underscore
  end
end

Задаёт base_name с учётом пространства имён текущего класса.

Rails::Command::TestCommand.base_name # => 'rails'
command_name () Показать исходный код
# File railties/lib/rails/command/base.rb, line 113
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'
default_command_root () Показать исходный код
# File railties/lib/rails/command/base.rb, line 137
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.

desc (usage = nil, description = nil, options = {}) Показать исходный код
# File railties/lib/rails/command/base.rb, line 32
def desc(usage = nil, description = nil, options = {})
  if usage
    super
  else
    class_usage
  end
end

Пытается получить описание из файла USAGE, расположенного на один уровень выше корневого каталога команды.

Вызывает метод суперкласса
engine? () Показать исходный код
# File railties/lib/rails/command/base.rb, line 26
def engine?
  defined?(ENGINE_ROOT)
end

Возвращает true, если приложение является движком Rails.

executable (command_name = self.command_name) Показать исходный код
# File railties/lib/rails/command/base.rb, line 80
def executable(command_name = self.command_name)
  "#{bin} #{namespaced_name(command_name)}"
end
hide_command! () Показать исходный код
# File railties/lib/rails/command/base.rb, line 53
def hide_command!
  Rails::Command.hidden_commands << self
end

Вспомогательный метод, позволяющий скрыть эту команду среди доступных при запуске команды rails.

namespace (name = nil) Показать исходный код
# File railties/lib/rails/command/base.rb, line 43
def namespace(name = nil)
  if name
    super
  else
    @namespace ||= super.chomp("_command").sub(/:command:/, ":")
  end
end

Вспомогательный метод для получения пространства имён из имени класса. Он работает так же, как стандартный метод Thor, за исключением того, что Command в конце имени класса удаляется.

Вызывает метод суперкласса
printing_commands () Показать исходный код
# File railties/lib/rails/command/base.rb, line 74
def printing_commands
  commands.filter_map do |name, command|
    [namespaced_name(name), command.description] unless command.hidden?
  end
end
usage_path () Показать исходный код
# File railties/lib/rails/command/base.rb, line 127
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.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API